Magento

How to Set Up Multiple Store Fronts with Magento

This tutorial will walk you through the setup of multiple store fronts running off one Magento back-end and database. Once we have set the store up in the database we will be exploring two methods of creating the store fronts on the physical server. The method you select will have to do with server requirements, how you wish your store to operate, and, to some extent, budgetary constraints.

Using separate directories for all stores
Works for all versions of Magento.

Using a shared directory for all stores
This is my preferred method. I find it to be the most expedient when working with a large amount of store fronts. This method works on all versions of Magento higher than 1.4

Create a New Store in Magento

To start off, 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:

Log in to the Magento Admin Panel.
If you want your new store front to use your existing root category, you may skip the category creation step.
Go to Catalog→Manage Categories in the top menu.
Click Add Root Category.
Create a new root directory for your multi-store Magento

In the Name field, enter your new store name. Under Is Active select Yes.

Click the Display Settings tab. Under Is Anchor, select Yes. Then select Save Category.
Setting the correct display settings for your new store root category
  1. Go to System→Manage Stores.
    Manage the store fronts in the Magento back-end
Click Create Website.
In the Name field, enter your new store name. In the Code field, enter a unique string without spaces.
Then click Save Website.
Set up your new Magento website

Click Create Store.
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 wish to use for the store front. Then click Save Store.
Create a new Magento store
Click Create Store View.
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.
Create a new store view inside your Magento back-end
Go to System→Configuration.
In the Current Configuration Scope, select the Website you just created.
Configure new magento store settings
Select the Web menu option, and expand the Unsecure and Secure sections by clicking them.
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.
Set up the store configuration for your new Magento multi-store front

You have successfully set up a Magento store. Repeat the steps above for any additional stores you wish to create.

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)

Ensure that the domain name you wish to use is pointing to the server.
Use the following guide to create a Secondary Domain for your new store.
Using either FTP or SSH, copy the .htaccess and index.php files from your Magneto Installation to the document root of your new domain.
Open the index.php file that you just copied over and edit the last line of the file as follows:
Change newstore to the Code you created when you set up the new website above. 
Mage::run('newstore', 'website');
Finally, using SSH, create the following symbolic links in the document root of your new domain:
Replace the path below with the full path to the document root of your Magento Installation.
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/skin/ skin
ln -s /home/example/example.com/html/var/ var
You have successfully set up 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)

Ensure that the domain name you wish to use is pointing to the server.
Use the following guide to create a Pointer Domain for your new store:
Make sure the Pointer Domain is pointing at the Primary Domain where your Magento Installation is located.
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
You have successfully set up your pointer domain to work with Magento. You may now load your new domain in your browser and begin developing your new store.

If SetEnvIf Doesn’t Work

Try the following:

Edit the .htaccess file in the document root of your Magento Installation.

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]

Hans-Eirik Hanifl

Hans-Eirik Hanifl is a forward thinking e-commerce and marketing consultant. As an advocate for the free exchange of knowledge, he founded E-Commerce Gorilla as a place where like-minded individuals can ask questions and share their expertise on practical solutions in the area of e-commerce and marketing. He is the owner of TRM Marketing and an avid supporter of the open source community.

Related Articles

2 Comments

  1. Hi There! This was a great post and has been a great help – but I wonder if there’s something else, or whether something has changed in Magento 1.9.1.0??

    I’ve set up my multiple stores using the second method that you suggest, but I’m struggling to get them to show specific home pages. I have created a second instance of ‘home’ in the CMS Pages section (and called it ‘home3’), but when I try to set them to point to each of the stores, I get a response on the front end that says ‘There was no Home CMS page configured or found’.

    If I set the home page as relating to the default store again it all works, but both domains show the same home page. It’s really key that I can show different home pages!!!

    I hope you still maintain the site, and I’d be really grateful if you have any pointers that may help.

    Many thanks,
    Dom

    1. Dom,
      The method of setting up multiple stores is the same in Magento CE 1.9.1. The issue you are most likely running into is you have not assigned your “Second Homepage” (assuming this is the page title) to the website/store inside the configuration. Please note, you don’t have to call the second homepage URL “home3” either, as they are unique to each website/store they can both have the same URL key of “home” if you wish.

      Navigate to System>Configuration and then under the “Current Configuration Scope:” drop-down select the website/store you wish to assign.
      Once this configuration scope has loaded open General>Web>Default Pages
      For “CMS Home Page” uncheck the “use default” option and instead select “Second Homepage”
      Save the configuration and refresh the website cache. Also Flush the Website cache for good measure.

      Also ensure that under CMS>Pages that “Second Homepage” is set to display under the second website/store under the “Store View” option of the pages interface.

Leave a Reply

Back to top button
Sign up to the E-Commerce Gorilla newsletter for updates & special promotions.
Join Our Newsletter
SUBSCRIBE
We value your privacy and protect your information like our own. Unsubscribe at anytime.