Magento Multistore setup via Apache conf

I commonly see developers on multistore Magento sites editing the root index.php for little or no reason. Here’s why.

One thing I commonly see when I go on client-site is that developers have altered the root index.php file to instruct Magento to load different stores based on the domain a customer arrives on. This is totally unnecessary and absolutely in the dev-operations domain.

One client had over 50 IF statements and would add more almost on a weekly basis as new store views came online!

Magento’s Index.php

Inside index.php there are 2 lines we need to pay attention too.

/* Store or website code */ 
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';

/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

Mage::run($mageRunCode, $mageRunType);

Both the following variables can neatly be set within your webserver config,



Here is an example of an Apache configuration.  As you can see the MAGE_RUN_CODE and MAGE_RUN_TYPE get set when the correct VirtualHost matches in Magento.

<VirtualHost *:80>
    DocumentRoot        /var/www/vhosts/magento/htdocs
    SetEnv MAGE_RUN_CODE "base"
    SetEnv MAGE_RUN_TYPE "website" 
<VirtualHost *:80>
    DocumentRoot        /var/www/vhosts/magento/htdocs
    SetEnv MAGE_RUN_CODE "store2" 
    SetEnv MAGE_RUN_TYPE "website" 


Why is this a better way?

Should your development team be making code changes just because you have a new domain name?  Why is such a fundamental file being edited needlessly when this should all be managed by your dev-ops team. (who by the way are also managing the new domains).


Buy Me A Coffee
back arrowBack to Index