How to set multiple stores/websites with one magento installation on different domains

Featured Image

This article will describe quickest way how to use and configure one Magento installation on different domains.
Point here is what do you want to have on that different domains, for example you want to have chosen categories/products on one domain and the other one will be on different language.
First you figure that and then go to configuration.

So for each domain you need to create webiste in main Magento admin installation:
System > Manage Stores > Create Website

For Name: you enter name of you desired domain (“my.website.com”)
For Code: you will enter identifier for that domain (“my_website_com”)

After that you will go to:
System > Manage Stores > Create Store

For Website: you will select “my.website.com” from dropdown menu.
For Name: I like to enter same as website (“my.website.com”) so I know for which website this store is but you can put here whatever you want.
Now for the Root Category: if you whish to have different menu for that website you will need to create new root category under
Catalog > Manage Categories > Add Root Category
in which you will put categories for that website.

And in the end you need to setup Store View under:
System > Manage Stores > Create Store View

Under Store: select “my.website.com” from dropdown menu.
For Name and Code enter “my_website_com”
And for Status: “Enabled”

If you wish to have diiferent language on that wesite you will need to change that on
System > Configuration
Under Current Configuration Scope: select your website/store from dropdown (“my.website.com”)
Under General tab go to
Locale Options and for
Locale choose language from dropdown (don’t forget to install language pack).

To run Magento on your different domain you need only two files:
.htacces
index.php

Open “index.php” and modify line which begins with “$mageFilename”
so it goes something like this:

$mageFilename = 'path_to_your_real_magento_installation_dir/app/Mage.php';

and line:

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

replace with:

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

Now you will also need media, skin and javascript files so you can also copy them into root folder of your new domain or you can set it from Magento admin:
Under Current Configuration Scope: select your website/store from dropdown (“my.website.com”)
Go to Web tab and under Secure and Unsecure you need to modify:
Base Skin URL (example: http://real.website.com/skin/)
Base Media URL (example: http://real.website.com/media/)
Base JavaScript URL (example: http://real.website.com/js/)

That’s it.
Enjoy coding!

19
Top

Enjoyed this post?

Subscribe to our RSS Feed, Follow us on Twitter and spread it to your friends!

Author

Vedran Subotic

Ex. Inchooer

Vedran worked in Inchoo from 2009 to 2012 as a backend developer.

Other posts from this author

Discussion 19 Comments

Add Comment
  1. Thanks for the helpful post. It means a lot to me because I want to learn Magento.

  2. Since Magento 1.4.x you don’t need to copy index.php file in Magento to run a different website. All of them can be easily handled with .htaccess rules by setting up environment variables.

    For example:

    SetEvnIf Host ^www\.domain1\.com^ MAGE_RUN_CODE=website_one_code MAGE_RUN_TYPE=website
    SetEvnIf Host ^www\.domain1\.com^ MAGE_RUN_CODE=website_two_code MAGE_RUN_TYPE=website
    

    These lines of code checks Host header in HTTP Request. In this case if domain name is http://www.domain1.com then will be initialized website with code “website_one_code” and if domain name is http://www.domain2.com then will be initialized website with code “website_two_code”.

  3. Sorry, there are typos in my previous comment, replace “^” character with “$” in at end of strings like “domain1\.com^”
    so it should be

    SetEvnIf Host ^www\.domain1\.com$ MAGE_RUN_CODE=website_one_code MAGE_RUN_TYPE=website
    SetEvnIf Host ^www\.domain1\.com$ MAGE_RUN_CODE=website_two_code MAGE_RUN_TYPE=website
    
  4. @ ivan. correct me if am wrong here but what is the point in putting multiple domain instructions into a single htaccess file?

    if i have domain1.com and domain2.com wont they need to be setup on separate hosting in order to resolve properly?

    in which case only the one htaccess entry needs to be made?

    or is there a way to send all of the different domain requests to one place at which point the correct store is then delivered?

  5. @Si Parker,

    Magento allows you to run absolutely different websites with different configurations via single point just by specifying Magento’s internal website code. So it means that if you configure your domain configuration and webserver configuration to manage two different domain names on the same server directory, then Magento will parse request and show up different Magento website instances depends on .htacces rules.

  6. Thanks mate.. nice post

  7. it work very well but don’t forget that “Redirect to Base URL if requested URL doesn’t match it” must be at false in Système/Configuration/ defaultshop web

  8. Hi Vedran,

    This is very informative post, and I did something like this for one of my clients. But I didn’t changed skin, media, and js paths.. only url.

    One problem I have, and I was thinking of asking here.

    Each domain have its root category and user for adding new products. But user from one domain can edit products and categories from another domain

    Is there a way to separete this permision issue ?

    Thanks for providing great magento resource for community

  9. How can i do this for version 1.5.1.0 to run on localhost ?

  10. RotorRian

    WOW !!! at least some decent info on this topic !!!!

    Hey Ivan if I 2x websites on magento

    http://store.visionup.co.nz and
    http://www.hidreplacements.co.nz what would my htaccess be because i keep on getting and internal server error ????

    SetEvnIf Host ^www\.store.visionup\.co.nz$ MAGE_RUN_CODE=basecode MAGE_RUN_TYPE=www.visionup.co.nz
    SetEvnIf Host ^www\.hidreplacements\.co.nz$ MAGE_RUN_CODE=altcode MAGE_RUN_TYPE=www.hidreplacements.co.nz

    Is this correct ?????

  11. Dan

    RotorRian – it should be like this:

    SetEvnIf Host ^www\.store.visionup\.co.nz$ MAGE_RUN_CODE=basecode MAGE_RUN_TYPE=website
    SetEvnIf Host ^www\.hidreplacements\.co.nz$ MAGE_RUN_CODE=altcode MAGE_RUN_TYPE=website

    You don’t need to put your domain name on the end. It actually has to say “website”

  12. @Ivan, @RotorRian, basically there is another typo: “SetEvnIf” should be “SetEnvIf”.

    I not tested this code by myself, but this should help )

  13. We need a single sign in between different stores in one installation. Is there a solution for this? We already use the Account sharing options for sharing userdata.

  14. Mike

    I have the following setup in magento 1.4.1.1.

    One magento install with several domain aliases.

    #Mage::run($mageRunCode, $mageRunType);
    switch($_SERVER['HTTP_HOST']) {
    	// Website A
    	case 'websiteA.com':
    	case 'www.websiteA.com':
    		Mage::run('websiteA');
    	break;
    	// Website B
    	case 'websiteB.com':
    	case 'www.websiteB.com':
    		Mage::run('websiteB');
    	break;
    

    Multistore runs perfectly without editing .htaccess

    Users can switch languages with the language switcher and stores with the stores switcher.

    However cart sharing and login sharing does not work.

    Can anybody help me with this?

  15. i create website and stores as you told the steps
    but where to copy the .htaccess file and index.php file for another website in magento installation?

  16. Is this possible to set different shipping for different store? In Magento ver. 1.5.1.0.

  17. Greg

    Hello Everyone

    I have a problem. I am looking to setup on Magento 1.7,, two domains each in a differnet language but i want to sell the same products from the same catalog.

    Is that possible or do i have to setup one domain with two different languages. the reason for setting up two domains is that they are different for different countries. but i am seelling the same thing.

    Please help

  18. How can we share customer on different website of same insatnce? help

  19. @Mike your code works! I have used it on magento 1.7.0.2

Add Your Comment

Please wrap all source codes with [code][/code] tags.
Top