Today I’ll explain how to setup multiple stores with different domains in a single installation of Magento.
Step 1: Add new root category for new store.
Go to Catalog > Manage Categories then click on “Add Root Category” to create new root category for each website. You set it to active and anchor.
Step 2: Create new website and store
Go to “System–>manage stores” to create new websites, new stores and new store views
Step 3: Set template for new website
Go to “system–>configuration” then choose the new website in “store select”, afterwards click on “Design” tab.
Step 4: Edit index.php
The most important part is: editing the content of index.php file. Open the file and find the following line at the bottom of file:
Mage::run();
Comment this line and add some new lines:
//Mage::run();
switch($_SERVER['HTTP_HOST']) {
//second website
case 'second_website.com':
case 'www.second_website.com':
Mage::run('second_website_code', 'website');
break;
//another website
case 'another_website.com':
case 'www.another_website.com':
Mage::run('another_website_code', 'website');
break;
//main website
default:
Mage::run();
break;
}
To customize this code to meet your own needs, just replace the domain names with your required domains, the website codes with your own website codes (in this example it’s the second_website_code:)
Mage::run('second_website_code', 'website');
I hope this help!
10 Comments
Thank you, this really solved a long lasting issue
PS just replace ‘website’ with ‘store’ if you wish to switch storeview
I’m a little bit confused do I need to install magento onto the other domain as well as the main store?
Hi I want to have different stores with completely different domains , all the domains are in the same server.
Please help me out I have a lot of questions about this , I tried your way and another ways but no one seems to be with the full directions
Hi!
I tried your method. It gives me this error “/home/mohal/public_html/magento3/app/Mage.php was not found”
Please, help!
Regards!
Hello Mohal,
Could you please check the existence of the file /home/mohal/public_html/magento3/app/Mage.php again? To help you solve this issue, I need to know the structure of your folder tree.
If you’re running each domain in a different virtualhost in Apache (with the same DocumentRoot), you can utilize the SetEnv directive to set the MAGE_RUN_CODE and MAGE_RUN_TYPE environment variables within your virtualhost to instruct Mage::run to run as the appropriate website.
For example, I use something like the following:
ServerName mysecondwebsite.com
DocumentRoot "/path/to/magento"
...
....
SetEnv MAGE_RUN_CODE "mywebsitecode"
SetEnv MAGE_RUN_TYPE "website"
Hello Michael,
Thanks for sharing. It’s very useful 🙂
Hello,
Could you please tell me more details of your group. Is it a Magento community? Thanks.
I read this paragraph completely regarding the difference
of most up-to-date and previous technologies, it’s amazing article.
No idea how many hours I’ve spent trying to get this working on VPS, trying things like editing the SSH but your blog gave me the answer so thanks a lot! And so straightforward as well!