How To Setup Multiple Stores With Magento
Magento Multi-Store & Setting Up Multiple Magento Stores Using One Admin Area
If you want to setup multiple Magento stores and multiple domains that share the same admin area, the tutorial below will assist you in doing so. This is very useful if you have a lot of stores that share the same or related products and you wish to manage it from one central location. You will also be able to track your sales and customers without having to login to the admin area of each website.
With the latest release of Magento Commerce it is much easier to set this up than it was in previous versions. Before it required you to modify the index.php file to handle your different domains pointing at different stores and various other complicated modifications. With Magento 1.4.x it is now much easier. The new index php contains the following code:
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
It checks two variables(code & type) and then uses them to run Magento. With the new code you’re able to set which store is supposed to be running under your main domain directly within your virtual host definition(root access required) or for our shared hosting and cPanel hosting customers you can actually now use .htaccess to accomplish this.
Creating your additional stores
If you haven’t already done so, the first thing you will need to do is setup your second store in the Magento admin area:
- Login to the Magento admin area.
- Go to the Catalog tab, then select Manage Categories.
- Click the ‘Add Root Category’ button on the left.
- On the right, for the Name, enter your secondwebsite.com. In the dropdown set Yes for both ‘Is Active’ and ‘Is Anchor’.
- Click on ‘Save Category’.
- Next you should go to the ‘System’ tab and select ‘Manage Stores’.
- Click the ‘Create Website’ button.
- For the Name enter your Secondwebsite.com, and for the ‘Code’ you should enter secondwebsite. You’ll be using this value later so make sure your note it down somewhere.
- Click ‘Save Website’.
- In the same area, click on the ‘Create Store’ button.
- For the Website, select your Secondwebsite.com from the dropdown. For the ‘Name’, you can enter Secondary Store. For the Root Category, select your now created Secondwebsite.com from the dropdown.
- Click the ‘Save Store’ button.
- Next click on the ‘Create Store View’ button.
- For the ‘Store’, select Secondary Store from the dropdown menu, make sure it’s for the created Secondwebsite.com. For the Name, you can enter English. For the ‘Code’, you should enter secondwebsite_en. For the Status, select ‘Enabled’ from the dropdown menu.
- Click on ‘Save Store View’.
- Next you will need to go to the ‘System’ tab and select ‘Configuration’
- For ‘Current Configuration Scope’ (located near the top left), change the dropdown menu from ‘Default Config’ to Secondwebsite.com.
- Select ‘Web’ from the left sidebar under the ‘Genera’l headline.
- For both the Unsecure and Secure sections, uncheck the Use default box next to the Base URL item, and enter the URL for your store, e.g. secondwebsite.com. Make sure to include the trailing backslash.
- Click the ‘Save Config’ button.
You’re almost done so hang in there!
Once you are finished creating the store, if you have not added your second domain as an add-on domain you will need to login to your cPanel account with us and create it as an Add-on domain now. Once you have done this you then need to copy your index.php and .htaccess file to the created directory for your add-on domain.
After copying over your index.php file, you should replace the following lines of code in the index.php file located only in the new add-on directory:
Replace this line:
$mageFilename = ‘app/Mage.php’;
With the following:
$mageFilename = ‘../public_html/app/Mage.php’;
Next you will need to either use the VirtualHost method(VPS and dedicated servers) or the .htacess method (for regular magento hosting / shared hosting accounts).
Using VirtualHost:
To set this up using the Virtualhost method you should simply add the following lines within your VirtualHost definition file:
SetEnv MAGE_RUN_CODE "base" #Put your main/base website or store code here.
SetEnv MAGE_RUN_TYPE "secondwebsite" #Here you should put 'secondwebsite' if the URL of the additional store you are adding is secondwebsite.com.
Using the .htaccess method:
If you do not have access to the virtual host file and are not a VPS or dedicated server customer, you can still use .htaccess for this.
In your .htaccess code you will need to define your main and secondary websites. For example if the URL of your main/base website is base.com and the URL of your second website is secondwebsite.com you should put the following code in your .htaccess
SetEnvIf Host .*base.* MAGE_RUN_CODE="base";
SetEnvIf Host .*secondwebsite.* MAGE_RUN_TYPE="secondwebsite";
You are, of course, not limited to using just 2 websites. To add additional stores you would simply add the additional lines of necessary code:
SetEnvIf Host .*thirdwebsite.* MAGE_RUN_TYPE="thirdwebsite";
etc.
You should now be all setup using Magento multi-stores and have multiple stores with one main admin area in Magento, without messing around with the code and the other previous lengthy methods
.
If you have any questions, additions or issues with this feel free to comment.

Very nice and useful information. This is especially good for beginners. Great Job done. Have bookmarked it. Keep coming up with some more.
If any files will put in the second website
I have been running 2 separate installations of Magento for 2 websites. I am of course trying to consolidate this. Is it necessary to remove all content from the add on domain folders in order to change the .htaccess? I feel like I have done everything correctly, however the old website still pops up. Thanks
Yes you should remove all the files in the add-on domain directory. Just to be safe you could always move them to a different created folder, such as /backup/, just in case you need these files again in the future.
The only files you should need are the index.php and .htaccess in the add-on domain folder.
Hi,
I have copied the index.php and .htaccess file to the created directory of the new website but apperas the following error:
app/Mage.php was not found
Should I install magento on the directory of the new website?
Thanks for your help.
Best regards
In the new index.php file try replacing the following line:
$mageFilename = ‘app/Mage.php’;
With this new line of code:
$mageFilename = ‘../public_html/app/Mage.php’;
I have updated the original article with this new information.
One last question, since I want create one web site for each language, how can I redirect the costumer to the right web site when he choose a different language?
Thanks again
Great article, we were working on this and had a problem where the site redirected to the base site, to fix this you can System–>Configuration–>General–>Web
Redirect to Base URL if requested URL doesn’t match it – setting this to No fixes the problem
This was an annoying issue for me! Thanks.
Which .htaccess file am I editing. The one on the root of mainDomain.com or the one we copied into MainDomain.com/SecondDomain.com/ or the .htaccess file on the root of the actual SecondDomain.com?
This may be answered by my first question, but how does SecondDomain.com point to MainDomain.com/SecondDomain.com/?
Thanks for the tutorial. I have followed it closely but get an Internal Error message on the addon domain which is http://www.tiendasdeljugueteseleccion.es
My doubt is if I need to change much the line that you add in index.php ie. do I keep the two full stops you have added before public_html? also I do not have a public_html in the second addon domain directory. I copied the index.php and .htaccess to the root there.
Finally, in the .htaccess file I filled in *juguetesadiezeuros as base both times and the secondsite is tiendasdeljugueteseleccion in both instances.
How come it doesn’t work? It seemed so simple
Thanks,
Iain
Hello
I would like to set up a multi-magento site where the Cart is shared.
I believe the easiest way to do this is using sub-domains???
Will these instructions work for sub-domains set up and will the cart be shared???
I like the simplicity of the .htaccess file changes as I am not very techie!
Thanks for any advice
I need the exact code with url that some one is using. Im not a .php coder, so the little things are going to be a bit over me. i can overwrite and change .php and make it work in most cases.
can some one post what their files actually look like?? the index.php and the .htaccess ??
that would help just about everyone that i have seen in the last 2 weeks online that are trying to figure this out.
Mike I am planning on doing this for everyone because I had spent hours trying to get it working too. My problem was simply that none of the tutorials I found online made it clear that you are just pointing your domain to your primary site and then modifying the htaccess file in a sub folder on your primary site with the name of the sister site. You do not need to pay for a second hosting account. I managed to get it working that way before I found that out. However I do not recommend that route both because it is harder and secondly why pay for a second hosting account, nomatter how cheap! Anyway I got my hands full right now but I plan on rewriting the tutorial! Until then enjoy your life you only have one!
Looking forward to it Eric. If you have anything to add or contribute feel free to let us know and we can update this and reference you.
What is the actual “VirtualHost definition file” that I need to edit?
I have two sites sitting on the same VPS – toggle.co.nz (base) and gravitee.co.nz (add-on). I’ve got all the Admin done, and my host told me I should use the “.htaccess method” instead of “VirtualHost”…
Quote: “Our control panel controls the VirtualHost entry so you don’t need to worry about it. You should be able to use setenv in your .htaccess file to set these environment variables for the website.”
However, am struggling to get gravitee.co.nz to pick-up the correct Mage.php from toggle.co.nz
My VPS is structured: /home/www// …. and my Mage.php is in /home/www/toggle.co.nz/app/Mage.php
My NEW index.php & .htaccess is in /home/www/gravitee.co.nz/public/index.php , and has the following line: $mageFilename = ‘…/toggle.co.nz/app/Mage.php’; >>> but browser can’t find it.
Appreciate any advice. Thanks.
Update…. I changed the index.php to hardwritten:
$mageFilename = ‘/home/www/toggle.co.nz/app/Mage.php’;
However, this just seems to act as a complete redirect to the BASE site, and does not pick-up the new WEBSITE/STORE settings of “gravitee”. My .htaccess seems to read correctly:
SetEnvIf Host .*toggle.* MAGE_RUN_CODE=”toggle”;
SetEnvIf Host .*gravitee.* MAGE_RUN_TYPE=”gravitee”;
I can’t decipher if this a Magento configuration or ServerSide configuration issue….. but everything looks solid in the System > Manage Stores & the BaseURL for gravitee in config reads: http://www.gravitee.co.nz/
Brick wall…………….. thud!
Todd, maybe check in the error_log or have your host check to see if it is throwing any errors. I would also double check in the admin area and make sure all settings are correct.
Bugger this….! Does someone want to earn themselves $50 and do this for me?
Todd I will do it for you. This will give me a reason to document it as I have wanted to do so and post it here as well as the official magento site! Contact me at magento@cfbits.com
Ha, I’ll do it for $250 maybe.
Yes he did low ball it. I will do it for $100 and that is uber low.
No sweat guys all done. Had done everything right, just that Fooman Speedster had to be reinstalled to pick-up the multi-store. All sorted now.
Love the “I’m worth $250 for an hours work efforts”… good call! Having now done this once, it’s a 20min setup at best.
Lol. I was going to joke around that it probably takes Matt hours if not days to get it done but I initially decided to bite my tounge.
Hi Todd,
How did you solve your problem? In my side too it act as a complete redirect to the BASE site!
Thank you for your help!
Michel, from his previous response it looks like he had the plugin ‘Fooman Speedster’ installed, which looks like it is a caching plugin. If you have it installed or a similar one you could try clearing the cache or reinstalling it. Also clear the cache in your /var/cache and /var/session folders.
I didn’t have that plugin installed & cache are off & deleted by FTP
The other trick that is missing is that you have to SymLink AddOn to Base…. all the /app /var etc….
However, I have recently hit issues with the caching folders which was breaking things. To fix this you have to create a /tmp directory on the add-on site as well.
I’ll do yours for $250 ;0)… going rate apparently…. LOL.
Hi Todd,
My second domaine name is parked under the first domaine name so if I understand well what you mean with “SymLink AddOn” I don’t need it because I do not have to redirect my domaine.
I’m closer to sent to you 250$…;-)