Madproject

Always know where your towel is.

Magento: One site, multiple domains

A client recently wanted 2 domains resolving to the same Magento instance. This is typically discouraged due to SEO concerns of duplicate data/information but I digress.

Depending on your DNS management, you’d probably “park” the 2nd domain over the primary domain… done and dusted.

Unfortunately, it’s not that simple with Magento due to its robust multi-site and URL rewriting system. Magento has multiple scope/layers that allow you fine grain control over what you want to share between site/store instances. You can read more about that here: Overview: How Multiple Websites & Stores Work

In our case, the client wanted both domains to resolve to the same site (same template, same products, same everything). This was performed in Magento 1.6.2 on a standard LAMP setup.

  1. Create a new store
    1. System->Manage Stores
    2. Create Store
    3. Fill in the store fields, taking care that the Website and Root Category are the same as your primary site.store

      Screen Shot 2014-02-21 at 11.33.27 AM

    4. Save Store
    5. Create Store View
    6. Fill in the store view fields, change Store to the new store you just created, give your store view a Name (spaces ok), a code (must be all lower case with no spaces) and make sure it’s enabled.

      Screen Shot 2014-02-21 at 11.37.24 AM

    7. Save Store View
    8. System->Index Management->Select All & Reindex Data
    9. Your new store which will be share everything with your primary store is now created
    10. Note your Store View Code as you’ll need it later
  2. Tell Magento where to look – part 1
    1. System->Configuration->Web
    2. Change the scope on the upper left to your newly created store view
    3. Change Unsecure->Base URL to your second domain (You’ll have to uncheck Use Website)
    4. Change Secure->Base URL to your second domain (You’ll have to uncheck Use Website)
    5. Save Config
  3. Tell Magento where to look – part 2
    1. Using your favourite IDE, open the .htaccess at the root of your Magento install
    2. Add the following, obviously changing the values with your own:
      SetEnvIf Host www\.mysecondarydomain\.com MAGE_RUN_CODE=yoursecondarystoreviewcode
      SetEnvIf Host ^mysecondarydomain\.com MAGE_RUN_CODE=yoursecondarystoreviewcode
      
  4. Finishing up
    1. Clear the cache for good measure: System->Cache Management->Flush Magento Cache
    2. You may need to change the scope of your CMS pages to show on all sites and now just your primary site/store: CMS->Pages->Update the Store View to All Store Views or individually select the applicable stores.

4 comments for “Magento: One site, multiple domains

  1. September 30, 2014 at 02:33

    Great, thanks!
    Was looking a long time for this information.
    I followed your instruction, but i see now that i have to change the scop of the reviews… and the static blocks…
    Lucas

  2. omar
    January 21, 2015 at 05:16

    Hello sir you actully creating storeview and there you assign the different urls. My Question is i have a complete one website with three storeviews (EN,DE,FR) i want to call this magento instance on multiple domains how can i do that please guide me i really need your help. thanks in advance

  3. March 26, 2015 at 08:38

    Great idea could it work for 3 sites

  4. July 25, 2015 at 16:53

    when i hit second domain on browser then it redirect to first domain.

Leave a Reply

Your email address will not be published. Required fields are marked *