Multiple Website Setup with Different Document Roots

Last modified by Magnus Wester on Wed, June 23, 2010 15:14
Source|Old Revisions  

This is an old revision of the document!


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.6, 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.


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.6) 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.

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:

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

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.
  5. require "";

The Root Folder Sitemap Files

To learn more about how to create sitemap files with Magento, you may first want to read more about creating Google Sitemaps for Magento sites.

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:

  1. // Link to the sitemap in the Magento directory
  3. // Prevent contents from being cached
  4. header("Expires: Fri, 14 Oct 1955 05:00:00 GMT");
  5. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  7. // Inform user agent that content is XML and is UTF-8 encoded
  8. header('Content-type: text/xml; charset=UTF-8');
  10. // Read sitemap XML file from Magento and render it.
  11. // Do not use http here as Zend doesn't seem to allow it!
  12. @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/product/view/id/
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/review/
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/product/view/id/
  • /catalog/product_compare/
  • /catalogsearch/
  • /cgi-bin/
  • /checkout/
  • /contacts/
  • /customer/
  • /downloader/
  • /install/
  • /images/
  • /js/
  • /lib/
  • /magento/
  • /media/
  • /newsletter/
  • /pkginfo/
  • /private/
  • /report/
  • /review/
  • /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:


Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs