Setting up Magento with multiple websites or stores

There are many tutorials how to set Magento to work with multiple stores and make different domains point at each store. Since release of Magento CE and Magento EE it is even more easy to do.

Magento evolves

Solutions used in previous versions required developer to modify index.php file to handle different domains pointing at different stores. New index php contains following code:

$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

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

So it checks two environmental variables and use them to start Magento runing. What does it give you? You can set now which store/website is supposed to be running under selected domain directly in virtual host definition or even htaccess.

VirtualHost solution

To benefit from this little piece of code it is enough for you to add following lines within your VirtualHost definition:

SetEnv MAGE_RUN_CODE "base" # put here your website or store code
SetEnv MAGE_RUN_TYPE "website" # put here 'website' or 'store'

.htaccess solution

If you have no access to virtual host definitions, you can still try to use .htaccess for that, putting within following lines:

SetEnvIf Host .*yourhost.* MAGE_RUN_CODE=base
SetEnvIf Host .*yourhost.* MAGE_RUN_TYPE=website

Where .*yourhost.* is an regex expression matching the domain for which you want to set environmental variable.

So now you are capable of setting up your Magento multiple stores website without messing up with the core. Good luck.

34 comments on "Setting up Magento with multiple websites or stores"

Rich's picture
Rich (visitor) - Sun, 10/01/2010 - 02:33:

I understand the code, I see the new field in the back-end, but why is type "website" or "store"?

Is this suppose to be set whether it goes to the Website or Store View?

Lucjan Wilczewski's picture
Lucjan Wilczewski - Tue, 12/01/2010 - 15:09:

@Rich: You are always on the Store View, but you may be on particular one, or default one. If you will use 'website' and will give Website code you will land on specified Website's default store's default Store View. If you will use 'store' and will give Store View code, then you will find yourself on the specified Store View.
As a matter of fact there is also a 'group' type valid, which would lead to default Store View for the Store, and it seems that code you have to provide in this case is the Store's (store_group) id value.

Dan Shields's picture
Dan Shields (visitor) - Thu, 11/02/2010 - 21:47:

I don't know if this is for every type of setup, but I found that for the .htaccess method you have to remove the quotes around the values and also the semi-colon like so

SetEnvIf Host .*yourhost.* MAGE_RUN_CODE=base
SetEnvIf Host .*yourhost.* MAGE_RUN_TYPE=website

Conec's picture
Conec (visitor) - Fri, 05/03/2010 - 16:25:

Hi, I am busy an all day and night trying to get this fixed and I do not succeed! Can you please help me?

I want to get URL's to website's

In advance thanks for your help!

conec's picture
conec (visitor) - Sat, 06/03/2010 - 21:50:

Hi, I am on Magento

Thanks for this post, I almost lost my hairs on that.

I made that on index.php:

$mageRunCode = isset($_SERVER[’MAGE_RUN_CODE’]) ? $_SERVER[’MAGE_RUN_CODE’] : ‘newbesite’;
$mageRunType = isset($_SERVER[’MAGE_RUN_TYPE’]) ? $_SERVER[’MAGE_RUN_TYPE’] : ‘website’;

And turn “Redirect to Base URL if requested URL doesn’t match it” to “NO” in the admin

It works for me to get to my “newwebsite”, but now I can get to my “base” website! or to other websites!
So how and what to configure for multi websites?


Laurent Clouet's picture
Laurent Clouet - Mon, 08/03/2010 - 11:37:

Hi Conec,

What code did you put in your .htaccess file? What is URL or your base and newwebsite?

For example if URL of you base is and URL of your newwebsite is you should put following code in your .htaccess

SetEnvIf Host .*base.* MAGE_RUN_CODE="base";
SetEnvIf Host .*newwebsite.* MAGE_RUN_TYPE="newwebsite";


Mike's picture
Mike (visitor) - Wed, 17/03/2010 - 17:38:

Hi, Mag I'm on a dedicated server.

I have set up my first 10 websites in Magento and pointed all 10 urls to my nameserver. In addition, I have set up each store within the admin to the correct urls. I tested them and they are all landing on the main domain, so I think I'm to this step now (correct me if I'm wrong please).

1. How would I change my index.php for multiple domains? Is this the best way to do multiple domains? In the end I might have close to 300 domains pointing to one instance of Magento.

2. I was told to park all of my domains under the Main domain in Cpanel where Magento is installed. Is this recommended?

3. Will these domains be able to share the same cart under one SSL?

Obviously, I'm new to all of this but trying to make my way through it so any feedback would be great. I think once I get the first few set up the other 200+ will be easy. I just want to make sure I get started in the right direction.

jai's picture
jai (visitor) - Thu, 01/04/2010 - 17:54:

It did not work. Can some one guide me how to add multiple sites. I dont know mush about it and if anyone can send steps then I will really indebted.

hardly urgent. pls help me.

Ste's picture
Ste (visitor) - Thu, 08/04/2010 - 16:18:

I’m currently running 2 websites from one Magento installation and I want to enable Web Server Rewrites for SEO. However, when I do this, I’m getting a 404 Not Found error for the page I’m navigating to. It works fine when rewrites are turned off.

Rewrites are enabled in Apache and rewrites do work on the base website. It just wont work on the external websites.

Any ideas?

Alex's picture
Alex (visitor) - Wed, 28/04/2010 - 03:35:

Here another simple solution:

if ($_SERVER['HTTP_HOST'] == ""){
$_SERVER["MAGE_RUN_CODE"] = "yourcode";
$_SERVER["MAGE_RUN_TYPE"] = "website";


$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';

Note: I set up the second store as website - not as store.

Daniel's picture
Daniel (visitor) - Sun, 16/05/2010 - 14:59:

Hi Mike,

I was wanting to know if you ever got this working? I am trying to do the exact setup as you are.
I have successfully set up a multi store environment, but I am unable to share the cart. I know I have something wrong and was hoping you could shed some light on this for me.
We have our own server and have setup the different Url's to point to the root document of the main site. Then I have the other domains parked.

In my index.php I have something like this....

switch($_SERVER['HTTP_HOST']) {
case '':
case '':

$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : 'site1';
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
Mage::run($mageRunCode, $mageRunType);

Can you tell me how you did it?

frank's picture
frank (visitor) - Wed, 19/05/2010 - 17:52:

hi, guys,
do anybody solve this ?
i am losing my hair everyday right now.
waiting for solutions....

frank's picture
frank (visitor) - Fri, 21/05/2010 - 09:29:

Hi ,
I have the problem like this(my service: debian+apache2+php5.26+...): and i am going to set different website to the same bacekend but with different IPs and SSL.
1,newly installed magento on "" with code "base", this domain has IP "IP1"
2,and then am i setup another visul host "" , which come with IP "IP2",
3,add new website to the back end with code "domain2"
4,as the expeirence of, i did copy index.php and .htaccess to the root fold of .../domain2/public_html/
5, reate symbolic links to point to the folds of /domain1/public_html/
6,then i add the code to ... /domain2/public_html/.htaccess

SetEnvIf Host .** MAGE_RUN_CODE="domain1";
SetEnvIf Host .** MAGE_RUN_TYPE="domain2"

and now when i try to access to, i got:
app/Mage.php was not found

Here i am totally new to magento, so can you please help to tell me where is the problem ? or did i do not need to step4-6, and only need to add the code to ../domain1/public_html/. htaccess ?

Thank you in advance.


Anonymous's picture
Anonymous (visitor) - Fri, 04/06/2010 - 11:25:


I don't understand your method
In my example i have one domain :
i create two store on the same domain :

what is the procedure for this configuration

Thank you in Advance

Hayden's picture
Hayden (visitor) - Wed, 07/07/2010 - 16:23:

I am also having trouble with this. I have one domain with multiple stores setup. I have one Magento installation setup on my domain ( I have setup two stores: retail, wholesale. I want my primary domain to be the retail store and would like my wholesale store to be a subdomain ( How do I setup my Magento Installation to do this? Thanks in advance.

Jonathan Day's picture
Jonathan Day (visitor) - Mon, 09/08/2010 - 06:41:

I found the same, it's necessary to remove the double quotes AND the semi-colon

sunil's picture
sunil (visitor) - Wed, 11/08/2010 - 15:10:

i have installed magento om my primary domian like now the url of this main domian is fine for me. now i have also create a another add on domain on how can i make the url for this add on domin like i dont want to include this StoreviewCode in add on domain url.please provide the solution how can i do it..thanks so much

Peter's picture
Peter (visitor) - Fri, 20/08/2010 - 16:04:

I am struggling with this for a few days now and tried every option discripted here. Unfortunatly I am not able to get everything working. I have got working 1 basestore and one substore, there is just 1 session made when I want to order on both of them, but I still have to seperate carts. I am working with version Does someone have a suggestion to try?

Thank you in advance.


mariek's picture
mariek (visitor) - Tue, 05/10/2010 - 20:16:

Maybe you have an idea:
In CPanel is the new domain2 installed as an addon domain.
I installed magento(single install 1.4) After that I created the second website with store and storeview and it has its own root directory.

Also I have switched the unsecure and secure base url link to {{unsecure_base_url}}domain2/ and created a new folder with index.php and .htaccess

After that I put this code in my .htaccess file in the root directory: RewriteCond %{HTTP_HOST} ^(.*)
RewriteRule ^ - [E=MAGE_RUN_CODE:codeofdomain2]

I have the error 404 page not found now on
SO what to do next?? Do I have to change some snippet in the index.php? I tried nearly everything...

Raphael's picture
Raphael (visitor) - Tue, 09/11/2010 - 02:55:


I got a problem. The store is switching but i do Not get a Session id.

What do im wrong?


frustrated's picture
frustrated (visitor) - Sun, 05/12/2010 - 08:27:

I have followed almost every tutorial available for this.

My is working fine.

My can load pages. It displays the categories assigned to this site. If you search for products, the products assigned to this site appear. But as soon as you click on a category or a product, you immediately receive a 404 error.

I've created a second domain, "added-on" it to my first domain, copied .htaccess and index.php and moved them to the folder of the second domain.

I've tried adding lines to .htaccess like suggested above, as well as the code given by Adrian to for the index.php file.

But still :(

Has anyone had this problem with the 404?

krite's picture
krite (visitor) - Tue, 07/12/2010 - 09:06:

I have put this code does not know that it is correct or not. .htaccess If not, how should suggest a solution thanks.

## If running in cluster environment, uncomment this

#FileETag none


SetEnv MAGE_RUN_CODE health123 # put here your website or store code
SetEnv MAGE_RUN_TYPE # put here 'website' or 'store'


[b]in my host[/b]

SetEnvIf Host .*yourhost.* MAGE_RUN_CODE=health123;
SetEnvIf Host .*yourhost.* MAGE_RUN_TYPE=;

[b]Remark : as defined in the code health123 Manager Store => website name => code.

and In My index.php

/* 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);


please help me again

david bill's picture
david bill (visitor) - Thu, 13/01/2011 - 06:40:

We have the same setup -- main site with two other domains which point to subdirectories that were created in the store root, so when the url is requested, it goes to the subfolders instead of the root folder and bypasses the .htaccess file where these rules are stored. Can anyone give me advice on how to solve that

michaeldf's picture
michaeldf (visitor) - Fri, 21/01/2011 - 21:22:

ok. this method seemed to work the best with the .htacess file.

i am with godaddy,
shared hosting account.
different url's

.htacess at around line 130 just after rewritebase /

I placed the following.

RewriteCond %{HTTP_HOST} ^(.*)
RewriteRule ^ - [E=MAGE_RUN_CODE:rs_site1code]

RewriteCond %{HTTP_HOST} ^(.*)
RewriteRule ^ - [E=MAGE_RUN_CODE:base]

where is
where is
where rs_site1code is the code for he webstore.

index.php modification is.


Im going to do a full set of instructions on magentocommerce when i finish making 1.4.2 work. because if anything the last two weeks has taught me that there is no real set of instructions on how to set up multiple stores using different variables. quite erking when you are trying to do this the first time.

Gui's picture
Gui (visitor) - Wed, 09/02/2011 - 17:29:

Does anyone have any experience with setting up multiple stores on subdirectories (,, etc.) under the one ‘website’?

If so, what is the difference between following this blog's method, and alternatively following the alternative advice stated here for example:
see comment no.13)?

The latter suggests that NO physical subdirectories are actually created but that they are “mimicked” by simply “setting Add Store Code to Urls to Yes in the Url Options section [and] Set the Secure and Unsecure URLs back to default.”

On the other hand, I believe that this blog's method - and similarly at -
entails actually creating physical subdirectories as well as modifying the index and htaccess files.

Can anyone explain the different rationales between these two methodologies please? Very confused!
Many thanks

Anonymous's picture
Anonymous (visitor) - Tue, 22/02/2011 - 18:18:
Hedda's picture
Hedda (visitor) - Fri, 18/03/2011 - 18:48:

No matter what, I still keep coming to this nice post, thanks to all of you :D

Magento Loewe's picture
Magento Loewe (visitor) - Fri, 01/04/2011 - 10:13:

Wow, i tried and tried and tried but it seems it will not work.
After some hours, close to depression i found my Mistake XD

Just forgot a ` in a line!! .. Damn little Signs :D

Thanks a lot for your introduction, it even helps for a german starter.

go on that way

george's picture
george (visitor) - Thu, 05/05/2011 - 09:08:

I have done the modifications you mentioned for running multiple domains single admin.

But when i go to the new store url(, it gets redirected to

Please help me in fixing this....

Michael Hostetler's picture
Michael Hostetler (visitor) - Sat, 25/06/2011 - 11:24:

I am considering doing a similar install one Magneto package to handle my three online stores, however it took me quite a bit of customization to bring one of my stores to function as part of my hosted SharePoint CRM. I'm wondering if I switch all these stores to one version of Magneto will that either, make them all connect to my CRM or in the worst case force me to re-do all my hosted SharePoint customizations?

Jakob's picture
Jakob (visitor) - Sat, 16/07/2011 - 23:33:

Hi, nice post!

I got this to work with one of my domains right away!

But i have a problem, i have a domain containing the character "æ" and i can't get that domain to go to other then the main store, i have tried to set the domain to the ASCII friendly domain name but that didn't work ether.

Any suggestions to a solution?

Cyberscripts's picture
Cyberscripts (visitor) - Wed, 10/08/2011 - 20:15:
Magento Designer's picture
Magento Designer (visitor) - Wed, 07/12/2011 - 14:31:

Great post. I found what I was looking for. Do you mind if I post this on my website and give you credit? If not, it’s ok.

Custom Web Design's picture
Custom Web Design (visitor) - Wed, 22/02/2012 - 07:07:

I am working in Magento but when i am trying to setup a blog inside Magento i get error.
please guide me.