3
votes

Is it possible to programmatically dispatch websites in Magento? Currently, I have a directory in the root of my site called /websites. In this directory I have subdirectories for each website, for example, site_a, site_b, site_c. Then each site subdirectory has a .htaccess and index.php with appropriate run code, for example:

$mageFilename = '../../app/Mage.php';
require_once $mageFilename;    
Mage::run("site_b", "website");

in the index.php in /websites/site_b. While this works, I do wish to avoid doing file management in the filesystem. Anyone can give any recommendation on the best way to do this? Perhaps a script in /websites that stands in place of the individual site sub directories. Any help appreciated.

3

3 Answers

3
votes

You have access to the $_SERVER variables in php and you can use these to determine the Mage::run("whatever", "website"); call, e.g.:

$whatever=$_SERVER['condition/url/whatever'];

// or use some cookies 

if (isset($_COOKIE['dev'])) $whatever=$_COOKIE['dev'];


switch($whatever)
{ case "example.com":
  case "www.example.com":
    $_SERVER['MAGE_RUN_CODE'] = "example";
    $_SERVER['MAGE_RUN_TYPE'] = "website";
    break;
  case "dev":
  case "test.com":
    $_SERVER['MAGE_RUN_CODE'] = "test";
    $_SERVER['MAGE_RUN_TYPE'] = "website";
  default:
    $_SERVER['MAGE_RUN_CODE'] = "live";
    $_SERVER['MAGE_RUN_TYPE'] = "website";
}
Mage::run($_SERVER['MAGE_RUN_CODE'], $_SERVER['MAGE_RUN_TYPE']);

In this way you only need one code base plus correctly configured settings in Magento backend to route to your different stores.

0
votes

You can handle all in .htaccess file mine looks like this:

#SetEnvIf Host www\.lenjerii\.com MAGE_RUN_CODE=base
#SetEnvIf Host www\.lenjerii\.com MAGE_RUN_TYPE=website
#SetEnvIf Host ^lenjerii\.com MAGE_RUN_CODE=base
#SetEnvIf Host ^lenjerii\.com MAGE_RUN_TYPE=website

#SetEnvIf Host www\.wildfashion\.ro MAGE_RUN_CODE=wildfashion
#SetEnvIf Host www\.wildfashion\.ro MAGE_RUN_TYPE=website
#SetEnvIf Host ^wildfashion\.ro MAGE_RUN_CODE=wildfashion
#SetEnvIf Host ^wildfashion\.ro MAGE_RUN_TYPE=website

This solution eliminate any other folders for your additional websites.

-1
votes

if I understand you correctly, what you need are some symbolic link: in each subdirectory, make symbolic link to the original installation. IE: ln -s ../app/ ./app.
Check out this tutorial