Magento – Magento2.1: How to create multiple websites with different domains

cloudmagento2multidomainmultistore

I deployed Magento 2.1 on console.google
Is there anybody who succeded to deploy multiple websites with different domains?
Magento2: How to create multiple storefronts
does not works for Magento 2.1

I am sure many people suffer the same issue?

There is not any answer to similar question for Magento 2.1 on link
How to setup another domain/website on the same Magento 2.1.0 installation? (updated)

Best Answer

You can create multiple websites or store views in Magento 2 admin panel and map unique domains to each of them.

Step 1: Point all domains to pub in Magento's root directory

Step 2: Configure domain names as base URLs for each website in System Configuration in Magento admin panel.

Step 3: Set store or website for each domain as environment variable in .htaccess of pub directory or in the webserver configuration.

  • Example with the websites as given in the question:

    SetEnv MAGE_RUN_TYPE website
    SetEnvIf Host abc\.com MAGE_RUN_CODE=domain1
    SetEnvIf Host xyz\.com MAGE_RUN_CODE=domain2
    
  • Example with store views instead of websites

    SetEnv MAGE_RUN_TYPE store
    SetEnvIf Host abc\.com MAGE_RUN_CODE=store_code_1
    SetEnvIf Host xyz\.com MAGE_RUN_CODE=store_code_2
    

    These configurations check if the domain contains "abc.com" or "xyz.com", which I find useful to also match subdomains or test systems like abc.com.testserver.com or test.abc.com, using the same .htaccess file. If you want exact matching, replace abc\.com with ^abc\.com$

Step 4: Clear cache and access your domains.

Related Topic