Multiple websites on Magento 1.4 single installation

Last modified by Magnus Wester on Fri, December 3, 2010 17:09
Source|Old Revisions  

This is an old revision of the document!

There are many ways multiple stores can be implemented. it could be:

  • subdomains in different document roots,
  • subdomains in same document root,
  • subfolders,
  • folder aliases,
  • etc.

To make it the most flexible we have made so the user will decide on the logic of which store will be launched from specific location.

All the logic should be done from index.php that is being ran.

As you can see in default index.php we have:

  1. Mage::run('base');

That means that ‘base’ store will be invoked.

In the demo download package we have multiple stores defined by subfolder they’re in.

For example German store is in /de/index.php:

  1. Mage::run('german');

If you have same index.php serves as entry point for few stores, the store code will have to be calculated from environment, for example host name:

  1. $host = explode(':', $_SERVER['HTTP_HOST']);
  2. switch ($host[0]) {
  3. case '':
  4.   $store = 'german';
  5.   break;
  7. default:
  8.   $store = 'base';
  9. }
  11. Mage::run($store);

Please note that .htaccess should be copied to every folder index.php is in.

Important: if you want your stores/websites to share the same cookies, you should fill the “Session Cookie management” section of the Web Configuration to /. Otherwise each store will have its own cookies, which means for example that if you are trying to use the cookie “store” (that contains the current storecode) for localization purpose, you may not have access to the expected cookie and the retrieved storecode may appear random.

Multiple Website Setup with Different Document Roots

When Magento is integrated with other server applications, things may get quite complicated. If you intend to provide a blog, a discussion forum and/or a chat server together with your Magento store, just parking all the domain names on top of a shared account may become impossible or at least increasingly messy to manage. Separating each Magento domain in a separate account allows you to integrate each store separately with the other web applications it needs in a much simpler fashion.

If this sounds interesting, read more about multiple website setup with different document roots.