Multiple Storefronts with Magento

This tutorial will show you how to set up multi-store functionality in Magento. Once you have created your new store, there are two different methods presented for implementing multi-store functionality at the server level:

Step 1: Create a New Store in Magento

The first step in setting up multi-store functionality is to create the new store(s) in the Magento Admin application. Follow the steps below to create a new store:

  1. Login to the Magento Admin Panel.
    NOTE: if you want your stores to share the same catalog and products, you may skip to step 6.
  2. Go to Catalog→Manage Categories in the top menu.
  3. Click Add Root Category.
  4. In the Name field, enter your new store name. Under Is Active select Yes.
  5. Click the Display Settings tab. Under Is Anchor, select Yes. Then select Save Category.
  6. Go to System→Manage Stores.
  7. Click Create Website.
  8. In the Name field, enter your new store name. In the Code field, enter a unique string without spaces. Then click Save Website.
    NOTE: This code will be used later, so write it down.
  9. Click Create Store.
  10. In the Website field, select the website you just created. In the Name field, enter a name for your store. In the Root Category field, select the Root Category you created above or use the default Root Category if you skipped ahead. Then click Save Store.
  11. Click Create Store View.
  12. In the Store field, select the store you just created. In the Name field, give your view a name (typically "English"). In the Code field, enter a unique string to identify the store view. Change the Status to Enabled. Then click Save Store View.
  13. Go to System→Configuration.
  14. In the Current Configuration Scope, select the Website you just created.
  15. Select the Web menu option, and expand the Unsecure and Secure sections by clicking them.
  16. For each section, deselect the Use Default box next to the Base URL and enter the URL for your store, including the trailing slash. When you are done, click Save Config.
  17. You have successfully setup a Magento store. Repeat the steps above for any additional stores you wish to create.

Step 2: Configure the Server to Load the New Store

Now that you have your new store created, you need to configure the server to load the right store. There are several methods for doing this. We present the two most popular methods below. The first method is the older of the two, and will work for any version of Magento. The second method takes advantage of changes made to the index.php file introduced in version 1.4.0.1.

Method 1: Separate Directories for Each Store (Using Secondary Domains)

  1. Ensure that the domain name you wish to use is pointing to the server.
  2. Use the following guide to create a Secondary Domain for your new store.
    How to add a Secondary Domain
  3. Using either FTP or SSH, copy the .htaccess and index.php files from your Magneto Installation to the document root of your new domain.
  4. Open the index.php file that you just copied over and edit the last line of the file as follows
    NOTE: change newstore to the Code you wrote down when you created the new website above.
    Mage::run('newstore', 'website')
  5. Finally, using SSH, create the following symbolic links in the document root of your new domain:
    NOTE: replace the path below with the full path to the document root of your Magento Installation.
    ln -s /home/example/example.com/html/404/ 404        # this is only in 1.3x
    ln -s /home/example/example.com/html/app/ app
    ln -s /home/example/example.com/html/includes/ includes
    ln -s /home/example/example.com/html/js/ js
    ln -s /home/example/example.com/html/lib/ lib
    ln -s /home/example/example.com/html/media/ media
    ln -s /home/example/example.com/html/reports/ reports       # this is only in 1.3x
    ln -s /home/example/example.com/html/skin/ skin
    ln -s /home/example/example.com/html/var/ var
  6. You have successfully setup your secondary domain to work with Magento. You may now load your new domain in your browser and begin developing your new store.

Method 2: Shared Directory for All Stores (Using Pointer Domains)

NOTE: These instructions will only work for Magento versions 1.4.0.1 and greater.

  1. Ensure that the domain name you wish to use is pointing to the server.
  2. Use the following guide to create a Pointer Domain for your new store:
    NOTE: the Pointer Domain will be pointing at the Primary Domain where your Magento Installation is located.
    How to add a Pointer Domain
  3. Edit the .htaccess file in the document root of your Magento Installation and enter the following just above the line RewriteEngine On:
    • Ensure that .*newstore.* matches the domain name of your new store.
    • Ensure that MAGE_RUN_CODE matches the Code you wrote down when you created the new website above.
      SetEnvIf Host .*newstore.* MAGE_RUN_CODE=newstore
      SetEnvIf Host .*newstore.* MAGE_RUN_TYPE=website
  4. You have successfully setup your pointer domain to work with Magento. You may now load your new domain in your browser and begin developing your new store.

Addendum: If SetEnvIf Doesn't Work

On some servers, particularly those running Litespeed Web Server, the SetEnvIf directive does not get recognized in the .htaccess file. If you are trying to set up multiple storefronts using Method 2 above, and it doesn't seem to be working, try the following:

  1. Edit the .htaccess file in the document root of your Magento Installation.
  2. Enter the following right below the line #RewriteBase /magento/:
    • Ensure that .*newstore\.com matches the domain name of your new store.
    • Ensure that MAGE_RUN_CODE matches the Code you wrote down when you created the new website above.
      RewriteCond %{HTTP_HOST} .*newstore\.com [NC]
      RewriteRule .* - [E=MAGE_RUN_CODE:newstore]
      RewriteCond %{HTTP_HOST} .*newstore\.com [NC]
      RewriteRule .* - [E=MAGE_RUN_TYPE:website]
 
multiplestorefronts.txt · Last modified: 2011/09/08 13:17 by whough