Page tree
Skip to end of metadata
Go to start of metadata



This document describes how to run multiple Magento domains with different document roots, e.g. in separate accounts on a VPS. In this setup, each domain name points to a separate account on the server, with a separate document root:


If you only intend to run Magento, there may not be any immediate advantages with using separate accounts, except perhaps that it constitutes a slightly cleaner approach that may be easier to manage.

When Magento is integrated with other server applications, however, things may get quite a lot more 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.

In this document, we will refer to the account where Magento is installed as “magentohome”, and to the accounts where Magento is running stores as “store1”, “store2” etc.

This example assumes that these accounts are used with Magento 1.1.8, PHP5 and the Apache web server in a Unix environment.

In the example setup, Magento is installed in /home/magentohome/public_html/magento/ and one of the store views is running from /home/store1/public_html/en/. In your setup, the format of these paths may be different; please consult the documentation for your web hosting environment.

We’ll use for http links to the account where Magento installed, and when we link to the store1 store.

Magento Installation


Install Magento as usual in the “magentohome” account.

Creating the First Store


The files needed to run store1 are all stored in the /home/store1/public_html/ directory.

In the example, we use a separate store view for each language we support in the store. To simplify bookmarking of pages in the store, we use a separate directory for each language/store view. Consider what folder structure best serves the store views you will be using.

The first language we support in this example is English. The files for the English store view are stored in/home/store1/public_html/en/.

The files we use for each store view are:

  • index.php
  • .htaccess

The files we use in the root folder for each store are:

  • index.php
  • .htaccess
  • http404.php
  • sitemap files
  • robots.txt

The Store View index.php File

In the example, each store view has its own directory, e.g. “/en”. Each of these directories needs the basic Magento index.php file to load /magento/app/Mage.php and issue the Mage::run call.

We need to make two modifications to this file: we need to provide the full path to the Magento directory, and we need to call the appropriate store view.

The full path to the Magento directory is /home/magentohome/public_html/magento/, so we modify the line where $mageFilename is set to

  1. $mageFilename = '/home/magentohome/public_html/magento/app/Mage.php';

The store view has been defined in Admin > System > Manage Stores as “store1en”, so we modify the Mage::run call to

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

The Store View .htaccess File

Each store view also needs a copy of the basic Magento .htaccess file in its directory, tailored to your requirements. As an example, if you run PHP5 in CGI mode, you may have uncommented the first few lines in the default Magento .htaccess file.

In this example, we only need modify the RewriteBase statement (near line 120 in Magento 1.1.8) in the default .htaccess file.

RewriteBase /en/

This tells the Apache server that everything that comes after the folder name in each URI is really parameters to the Magento index.php file.

Running Magento without URL rewrites

Using URL rewrites can create a lot of problems later, when you want to run other content delivery systems (blogs, forums etc) in the same language folder. Since all requests for content in the “en” folder will be rewritten to the Magento index.php file, it will be difficult to run anything else but Magento.

A more flexible approach is to rename the index.php file to something more search-engine-optimized, e.g. “buy”. Your baseURL will then become

which doesn’t look that bad. To tell the Apache server that “buy” should be run through the PHP interpreter, you need to add code similar to the below example to your .htaccess file. The way to do this varies slightly between Apache versions, however.

<Files buy>
ForceType application/x-httpd-php

The Root Folder index.php File

The main purpose of the index.php file in the root folder of the example setup is to activate the default store view, in our case by doing a redirect to the “en” directory. We accomplish this with the below index.php file:

 // /
// Used in multi-language environments to pass control to
// the index page in the default language folder
// Ensure the cached copy is ignored
// Expiration date is in the past
header("Expires: Fri, 14 Oct 1955 05:00:00 GMT");
// The page has always been modified since you saw it last
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1 (do not use no-cache)
header("Cache-Control: must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");
// Set the correct response code
header("HTTP/1.1 307 Temporary Redirect");
// Redirect the browser
// Make sure that any code below does not get executed when we redirect.

The Root Folder .htaccess File

The .htaccess file in the root folder

  • turns off directory browsing
  • tells the Apache server to use index.php as the default file
  • activates the Magento http 404 “Not Found” page for the entire site, even outside the Magento folders.
Options -Indexes
DirectoryIndex index.php
ErrorDocument 404 /http404.php

The Root Folder http404.php File

Magento has it’s own handler for http 404 “Not Found” errors, and in the Demo Store display the “no-route” page in the Magento CMS for 404 errors. This feature only works when the URI is correct up to and including a Magento folder name, so that the Magento index.php file is run. In our example, any incorrect URI beginning with “” will take the user to the “no-route” page.

If the URI begins with ““, however, Apache will signal the http 404 error to the default 404 error handler designated by the .htaccess file in the root folder. In the example, the http404.php file will be run. Our objective is to show the Magento “no-route” page for all “Not Found” errors, so we create a http404.php file that looks like this:

  1. // Default http 404 not found error handler.
  2. // The 404 status is already set here.
  3. // Just call the "not found" page in the default language folder.

The Root Folder Sitemap Files

Magento can generate a sitemap file for a single store view, but unfortunately not yet for a whole store or website. This means that you will have to submit each sitemap file separately to the search engines, preferably via the robots.txt file as shown below.

Most (if not all) search engines require that a sitemap is located in the domain it describes. Magento can only generate sitemap files in the Magento directory or a subfolder of it, e.g. /home/magentohome/public_html/magento/. When Magento stores are run with separate document roots, you must make the sitemap appear to be present in the document root of each store, e.g. /home/store1/public_html/.

In the example, the XML format sitemap file generated by Magento is located at/home/magentohome/public_html/magento/store1en_sitemap.xml. We now create a file called/home/store1/public_html/store1en_sitemap.php:

 // Link to the sitemap in the Magento directory
// Prevent contents from being cached
header("Expires: Fri, 14 Oct 1955 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// Inform user agent that content is XML and is UTF-8 encoded
header('Content-type: text/xml; charset=UTF-8');
// Read sitemap XML file from Magento and render it.
// Do not use http here as Zend doesn't seem to allow it!
@readfile ('/home/magentohome/public_html/magento/store1en_sitemap.xml');

The Root Folder robots.txt File

The robots.txt file is mainly used to exclude one or more directories or files from indexing by the search engines. The robots.txt file format is described at Note that many search engines allow the use of wildcards, support the setting of crawl rates, allow sitemap links and other more recent additions to the robots.txt standard, while others only support the basic Disallow directive.

Magento often provides many ways to reach a particular page, e.g. by the full /catalog/product/view/id/ link to a product page in the catalog, or using the URL rewrite for the page. The main reason for excluding directories from indexing is to have the search engine use only one distinct, preferred address for each page. A small robots.txt file for a Magento site can look like this:

User-agent: *
Disallow: /en/catalog/category/view/
Disallow: /en/catalog/product/view/
Disallow: /en/catalog/product_compare/
Disallow: /en/catalogsearch/
Disallow: /en/cgi-bin/
Disallow: /en/checkout/
Disallow: /en/contacts/
Disallow: /en/customer/
Disallow: /en/newsletter/
Disallow: /en/poll/
Disallow: /en/review/
Disallow: /en/sendfriend/
Disallow: /en/wishlist/

With Magento, there are many more directories that you may want to exclude from indexing. If you search the Magento forums, you will see recommendations to exclude one or more of the following directories for a Magento site:

  • /index.php/
  • /404/
  • /admin/
  • /api/
  • /app/
  • /catalog/category/view/
  • /catalog/product/view/
  • /catalog/product_compare/
  • /catalogsearch/
  • /cgi-bin/
  • /checkout/
  • /contacts/
  • /customer/
  • /downloader/
  • /install/
  • /images/
  • /js/
  • /lib/
  • /magento/
  • /media/
  • /newsletter/
  • /pkginfo/
  • /private/
  • /poll/
  • /report/
  • /review/
  • /sendfriend/
  • /skin/
  • /tag/
  • /var/
  • /wishlist/

For the more advanced search engines, you may specify a delay between each access to your site, e.g. 5 seconds. It is also possible to avoid indexing any URLs with parameters, e.g.

User-agent: msnbot
Crawl-delay: 5
Disallow: /*?

At the end of the robots.txt file, you should insert a link to each of the sitemap files for the site.

Sitemap: http:/
Sitemap: http:/
Sitemap: http:/
Sitemap: http:/
Sitemap: http:/

An example of a complete robots.txt file for a Magento site can be found here:

Modifications to the Magento Configuration


You configure each website, store and store view in Admin > System > Configuration. You must assign the base URLs for each store view on the Web tab, and set your design options on the Design tab.

Before you do this, you may need to add your new web site with its stores and store views to your installation using Admin > System > Manage Stores. 

Three Magento directories must be accessible from all domains running Magento:

  • The skin directory that contain the CSS, images and JavaScript for your themes
  • The media directory, where all the product images are saved
  • The js directory where most of Magento’s JavaScript code resides

In Admin > System > Configuration > Web you specify the location of these directories for all your stores. You basically have three options: point to the main magento directories for each website, copy the three directories to each website, or use symbolic links.

Use the Magento Directories For All Websites

The Magento installation includes all the files you need. In theory, you can simply link all your websites to the main Magento folder with the following settings in Admin > System > Configuration > Web > Unsecure:

and the following settings in Admin > System > Configuration > Web > Secure:

The main issue with this setup is if the secure pages on really can include secure content from, which has a different SSL certificate. If you know the answer, please update this section!

Copy Important Magento Directories To All Websites

To get around the possible SSL problem discussed above, you can just copy the three folders from to, etc, e.g. using SSH with root access:

cp -avf /home/magentohome/public_html/magento/skin/frontend/ /home/store1/public_html/magento/skin/frontend/
cp -avf /home/magentohome/public_html/magento/media/ /home/store1/public_html/magento/media/
cp -avf /home/magentohome/public_html/magento/js/ /home/store1/public_html/magento/js/

Since all the three directories have been copied to, you can use the following settings in Admin > System > Configuration > Web > Unsecure:

and the following settings in Admin > System > Configuration > Web > Secure:

The main disadvantage with this solution is that you must propagate all updates to your Magento installation - new product images, new scripts or new themes - to all your websites before you can use them. If you work a lot with your site’s contents or design may need to run the above copy job quite often.

Using Symbolic Links For the Important Magento Directories

To avoid the inconvenience of having to copy all the files to all your Magento-driven websites, you may use symbolic links in the server’s file system. Symbolic links can be used to make directories in one account accessible also in the directory structure of another account.

To access these three directories using symbolic links, open an SSH connection to your server and login with root access. Then create symbolic links to the three Magento directories using this sequence of commands:

cd /home/store1/public_html/
mkdir magento
cd magento
ln -s /home/magentohome/public_html/magento/media/
ln -s /home/magentohome/public_html/magento/js/
ln -s /home/magentohome/public_html/magento/skin/

You have now created “aliases” for the three Magento folders for store1. The symbolic links allow you to reference all the related files in the domain even though they are only stored on

This allows you to use the following settings in Admin > System > Configuration > Web > Unsecure:

and the following settings in Admin > System > Configuration > Web > Secure:

Using symbolic links can possibly impact the security of your websites. If you know more about this, please update this section!



  • No labels