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.
- Create a new store
- System->Manage Stores
- Create Store
- Fill in the store fields, taking care that the Website and Root Category are the same as your primary site.store
- Save Store
- Create Store View
- 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.
- Save Store View
- System->Index Management->Select All & Reindex Data
- Your new store which will be share everything with your primary store is now created
- Note your Store View Code as you’ll need it later
- Tell Magento where to look – part 1
- Change the scope on the upper left to your newly created store view
- Change Unsecure->Base URL to your second domain (You’ll have to uncheck Use Website)
- Change Secure->Base URL to your second domain (You’ll have to uncheck Use Website)
- Save Config
- Tell Magento where to look – part 2
- Using your favourite IDE, open the .htaccess at the root of your Magento install
- 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
- Finishing up
- Clear the cache for good measure: System->Cache Management->Flush Magento Cache
- 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.