Lately, we’ve been receiving a lot of questions on whether or not it would be possible to set up more than one webshop in a single Magento installation. Magento does indeed have this option, but the exact implementation may differ from case to case and from shop to shop. Another question we get a lot is “How do I set up an extra domain in Magento?”. To take away some of the mysteries and questions, we’ll give a brief explanation about how we have set up multiple Magento stores in one installation.

Extra domainnames in Magento

Every shop requires its own domain name. Say we sell exotic animals like camels (kamelen in Dutch) and we would like to open an online shop. First of all we would have registered the domain name www.kamelen-online.nl with Byte’s Magento hosting services. We chose a package with some extra diskspace so the extra shops and products should fit nicely.
Because we want to sell these animals both in the Netherlands and abroad, we registered a second domain: www.camels-online.com. We also have dromedaries for sale, so we registered a third domain: www.dromedaris-online.nl.
At Byte, we get a Presence hosting package with these names, as these allow us to setup a Server Alias to connect these domains to the existing hosting space (www.kamelen-online.nl in our example).

Websites, stores, views…Stores en Websites

Before we continue, it is important to understand the difference between some common Magento terms: Websites, Stores and Store Views.

  • The difference between a Website and a Store, is that a websites only contains customer data but no products and categories.
  • Stores are the real shops. They contain all the products that the shop offers. Stores may have one or multiple Store Views.
  • Store Views are the different ways the Stores are being presented. For example, you could setup a different Store View per language.

Every Magento site will always have at least one Website, one Store and one Store View, all created in the Magento Admin interface (under System –> Manage Stores). In our case (www.kamelen-online.nl) we set up the following:
We created one Website, called ‘Kamelen site’, with one Store, called ‘Kamelen shop’. We gave this Store two seperate Store Views: one in Dutch and one in English.
We also created a second Website called ‘Dromedaris site’, with one Store and only one Store View.
When creating Store Views, Magento asks for a code to use to reference these Store Views. We chose for ‘kamelen_nl’, ‘kamelen_en’ and ‘dromedaris’. These codes are important as we will need them later on to connect them to the domain names.

Magento Multistore Settings
Magento Multistore Setting

 

Connecting Domain names to Store Views

One of the first things Magento does when it loads is start up the Store View. Normally it starts the default Store View, but obviously you can change this, i.e. based on the domain the user is visiting to get to the website. The only thing we have to do is determine what Store view is being visited and start Magento with the code of that store front.
It’s not yet possible to connect domainnames with Store Views through the Magento backend, but luckily, this is a very simple procedure as you only need to change one file. Which file that is, depends on the version of Magento you use.

Connecting domains in Magento 1.3

In Magento 1.3 you can connect the domain name and Store View through the index.php file. This file loads all Magento files and subsequently starts the Website. Look for the following line in PHP:

Replace this line with the following:

Connecting domains in Magento 1.4

One of the differences between Magento versions 1.3 and 1.4 is that the code for detecting specific store fronts was removed from the default Magento files. This prevents all Store Views ending up at the same Website, or worse, a total breakdown of Magento, after upgrading the webshop.

Extra patch for Byte Hosting

At Byte Internet we use the ‘suExec’ principle for our webhosting, however the usual way to choose a Store View in Magento isn’t 100% compatible with this extra secured Magento setup. ‘suExec’ keeps your site extra secure, as it prevents unauthorized users from accessing your files. It also cleans up the environment variables to prevent your site from behaving differently due to them. Unfortunately Magento uses these environment variables to determine which Store should be loaded.
In order to make use of the variables stored in the environment you need to make a small adjustment to the index.php file. Around line 75 you’ll find the following line:

Replace this with:

Once you’ve made this change, Magento will know to also check the cleaned up environment variables to determine what Store View to load.

In Magento 1.4, the logic to determine the right shop is in the .htaccess file. This file sets up the environment variables that the index.php file will then consult to know what shop to load.

In the .htaccess file we added the following lines:

In this example there are 3 different Stores. All domains ending with ‘kamelen-online.nl’ will lead to the ‘kamelen_nl’ Store. ‘camels-online.com’ will lead to the English Store and ‘dromedaries-online.com’ is setup as well.

Configure different shops

Magento Config Scope
Magento Config Scop

The only thing left to do is setup the different stores in Magento. By default, the settings for all Stores are automatically the same as the Website settings and those in turn are linked to the global settings. You can change settings on al levels, and have them propagate downwards. You can change between levels by selecting the appropriate view, shop or global level in the drop down menu found in the Magento configuration editor in the top left.

The most important thing to change, is the base URL. You’ll find the setting in the Magento backend under System\Configuration\Web\Unsecure and \Secure. We’ve put the URL’s that Magento uses as the standard URL at all levels.

In our example under “Default Config” we’ve used “http://www.kamelen-online.nl/” as base URL as this is the main domain. The English version under “Kamelen Store” has http://www.camels-online.com/” as it’s base URL “, and the ‘Dromedarissen’-version obviously has “http://www.dromedaris-online.nl/” . If these shops have a HTTPS / Secure version as well, then you should also fill in the https-base-URL’s under “Secure”.

 

Magento baseURL settings
Magento baseURL settings

 

Obviously, creating different stores is just the beginning. There are still many options left in the Magento Admin Panel, but for now, we’ll leave it at this. If you have any tips or tricks for multiple Magento stores, feel free to let us know!

  • Erik Pluijmen

    We have fixed and added to the blogpost by explaining a little more about base url’s. We hope that users who experienced 404 errors before don’t run into them anymore

  • http://www.itbiz.com.br Lucas

    Do you know, please, how to setup multiple stores with multiple backends in one single magento install?

  • Cipriano Groenendal

    Hi Lucas,

    While I think it is possible to do this, I wouldn’t know of a simple way to get this up without applying a lot of hosting environment specific magic. You might be able to have a different local.xml selected dependent upon which Hostname is requested using a .htaccess or additions in the index.php, but i wouldn’t know a solution off’ the top of my head.

    Personally I would advise against it, since this could cause quite a few problems, such as:

    Different shops wanting to use the same theme but with slight changes for one of them.
    Different shops wanting to use different modules, but all of them being installed for all shops.
    Different shops needing to use different Magento versions instead of the same
    Different shops saving media with conflicting filenames

    if you still wish to use multiple stores in one single install, I wish you good luck.

  • http://about.me/hans2103 hans2103

    successfully tested on Magento 1.7
    The tutorial how to create a multistore Magento installation for Magento 1.4 also works for Magento 1.7

    change index.php because of suExec and change .htaccess with the redirects.

  • Willem Derks

    does anybody know how many subshop you can make!

  • http://about.me/hans2103 hans2103

    I’ve seen an interesting forum post about your question on the forum of Magento.com. Someone was asking if a single Magento installation could hold 500+ shops.

    it is possible to create such huge amount of shops… if you have enough servers to process them. But… and that’s a fair question off forum user Sonassi. “What are you trying to do exactly that you believe would require 500+ store views?”

    Please read the forum post on Magento.com about “Maximum number of stores and store views” -> http://www.magentocommerce.com/boards/viewthread/283877/

  • Matias Covarrubias

    Hi Hans,
    I am having issues with the multstore on Magento 1.7. Can you please send me the link the tutorial and I will be happy if you can providem de details of you success. Regards

  • http://about.me/hans2103 hans2103

    Hi Matias,

    I was referring to this blogpost (http://www.byte.nl/blog/2010/08/24/multiple-stores-in-one-magento-install). Cipriano explains how to install a Multistore Magento installation for both Magento 1.3 and Magento 1.4
    The explanation for Magento 1.4 also works for Magento 1.7

    succes

  • Mitrajit

    very helpful tutorial….
    I have similar and little bit extra problem.

    I have two websites and their corresponding store in one magento installation as you see in the attached image.
    Now also I have two domains —
    i) craftsmandir.in read as URLA and
    ii) craftsmandir.com read as URLB

    I assigned URLA for the store craftsmandir_in and only accessible form India and URLB for the store craftsmandir_com and accessible from rest of the world. If someone from India try to open URLB, then it must redirect to URLA and its corresponding store.
    Similarly if someone try to open URLA outside India it must redirect to URLB and its corresponding store.

    But I can’t do it, i don’t know where is my fault.
    Please help me.
    Thanku.

  • http://about.me/hans2103 hans2103

    Hi Matriajit,

    Thank you for comment. Glad to read that you think this tutorial on how to install a multi store Magento website in one Magento installation.

    Your issue is not covered in this tutorial therefor you cannot find your answer in it. To solve your issue you need a bit of PHP knowledge. Before you start programming it’s good to write things down. Just like you started doing.

    IF location-of-visitor = location-of-India AND url = URLA
    THEN open-magento-store = craftsmandir_in
    ELSE redirect-to URLB
    ENDIF

    IF location-of-visitor = !location-of-India AND url = URLB
    THEN open-magento-store = craftsmandir_com
    ELSE redirect-to URLA
    ENDIF

    I think this can be done in PHP easily. It’s up to you how to find out when a user is in India or not. Perhaps an IP-range will do.
    If someone else has a great idea, please add yours. Otherwise it’s wise to post your question on magento forum or stackoverflow.com I see a lot of great responses over there.

  • Iason

    Can we use this method also for Magento 1.7.* ?

  • http://about.me/hans2103 hans2103

    please read the other comments of this blogpost.

  • jitu

    Hi All

    I am new in magento but I have 6+ exp in development I want to know how can I create modules in magento I don’t understand the config.xml or other xml file how can I use them Its very headache for me If you have any trick or any think for me please share with me.

    Thanks
    Jitu
    Rjinfosys.co.in

  • http://about.me/hans2103 hans2103

    Hi Jitu,

    Best thing you can do is ordering the Packt Pub book “Mastering Magento” by Bret Williams.
    http://www.packtpub.com/mastering-magento-for-developers-designers-store-owners/book

    Read and learn…