Magento is a flexible eCommerce platform that allows you to manage multiple stores and frontends from a single Dashboard. A single installation can be configured as such so that multiple subdomains are spread out among multiple stores but managed singularly and can even share common product catalogs, customers and settings, depending on the setup!

 

 

Before We Begin

 

First thing’s first, we need to have a clear understanding on your options on how the stores should be addressed – the URL layouts for your setup. There are 3 approaches:

  1. Domains: e.g. www.store1.com and www.store2.com
  2. Subdomains: e.g. store1.website.com and store2.website.com
  3. Folders: e.g. www.website.com/store1/ and www.website.com/store2/

This tutorial will cover #2, Subdomains and will detail how to set-up a multi-store Magento installation with Subdomains.

 

For the set-up, make sure that the prerequisites below are met:

  • Magento must already be installed and on the root of a domain (www.example.com, not  www.example.com/magentofolder)
  • Access to add new vHosts (virtual hosts). If the hosting server has cPanel, it is already supported.

 

Alright, are both conditions checked? Good, now let’s get started!

 

1. Server Configuration

 

  1. Log into the server’s cPanel and open Subdomains.
    cPanel Subdomain
  2. Fill in the Subdomain’s name for the selected domain and make sure to set the Document Root to /public_html/. Click Create.
    cPanel Subdomain2
  3. Repeat Step 2 depending on the number of subdomains needed.

 

 

 

2. Creating a new Magento Store

2a. Creating Store Categories

If you want your websites to share the same catalog and categories you can skip this step.

  1. Log into your Magento Dashboard
  2. Click on Catalog » Manage Categories
    Store Category
  3. Click on Add Root Category
    Store Category2
  4. Enter a name for the new category and make sure Is Active is set to YES
    Store Category3
  5. Click on the Display Settings tab and set Is Anchor to True. This will show products listed in sub categories, and also enable product filtering for the category.
    Store Category4
  6. Click Save Category near the upper-right corner.

 

 

2b. Configuring the Stores

Before we start configuring our stores, lets pause for a minute and explain the concepts of Websites, Stores, and Store Views in Magento. Websites are the top-most entity in Magento. If you want completely separate sites that do not share cart, shipping methods, etc., you should create separate Websites. Each Website has at least one Store, and each Store has at least one Store View. Multiple Stores can share cart, user sessions, payment gateways, etc., but have their own catalog structure. Finally, a Store is a collection of Store Views. Store Views change the way pages are presented, normally used to offer a site in different layouts or languages.

  1. On Magento’s Dashboard, go to System » Manage Stores
    Store Config
  2. Click Create Store.
    Store Config2
  3. Enter the following:
    • Name – enter a name for the store;
    • Root Category – select the category you created in the previous step.
      Store Config3
    • Click Save Store when finished
  4. Note our newly-added store on the list. Click Create Store View.
    Store Config4
  5. Enter the following:
    • Store – select the store you created in the previous step
    • Name – enter a name for the store view
    • Code – enter a unique identifier for this store view
      Make a note of this code as you will need it later!
    • Set Status to Enabled
      Store Config5
    • Click Save Store VIew when finished.
  6. Now, go to System > Configuration
    Store Config6
  7. Make sure Default Config is selected as the Current Configuration Scope. Open the Web tab under General on the left sidebar of the page and open the URL Options section. Set Auto-redirect to Base URL to No.
    Store Config7
  8. Now, change the Current Configuration Scope dropdown to your newly created website (in this case, New Store View)
    Store Config8
  9. Under the Web section, we now need to change the Secure Base URL and Unsecure Base URL settings. Uncheck the Use Default [STORE VIEW], and replace the URLs with your corresponding domain name. Remember to include the trailing /. Click Save Config when finished.
    Store Config9

This completes the configuration of the new store. Repeat the steps above for every additional Store (subdomain) you want to add.

 

 

3. Mapping the domain on .htaccess

 

Now that we have added new Subdomains on the server and created new Stores inside Magento, it’s time to bring them together and map the correct Store to each Subdomain.

  1. Open the .htaccess file located on the root folder of your server (/public_html/) where Magento is installed. Make sure to check Show Hidden Files (dotfiles) when opening cPanel’s File Manager or use Adobe Dreamweaver or a similar editor.
  2. Add these lines on the bottom of the file (replace them with actual domain names)
    SetEnvIf Host www.subdomain.yourdomain.com MAGE_RUN_CODE=newstoreview
    SetEnvIf Host www.subdomain.yourdomain.com MAGE_RUN_TYPE=store
    SetEnvIf Host ^subdomain.yourdomain.com MAGE_RUN_CODE=newstoreview
    SetEnvIf Host ^subdomain.yourdomain.com MAGE_RUN_TYPE=store
    
    • MAGE_RUN_CODE – this is the unique code chosen when you created the Magento Store View
    • MAGE_RUN_TYPE – depending on whether you want to load a specific Website or Store View; set it to website or store, respectively. In our case, we will set them to store as we have set them the subdomains as such.
  3. Add an entry for each additional subdomain set up.
  4. Save the .htaccess file.

Now navigate to you new site and verify that the correct Magento store is loaded. If not, make sure that the the MAGE_RUN_CODE match the one created earlier and that the domain resolves to the correct folder/path.

You should now be able to see each respective store by browsing the URL.

Thank you for reading this tutorial!

1 Comment

Comments are closed.