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)

2 Answers 2


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.


I got it:

In the config for your stores, just enter the URLs as they are, not the install URL. Then, on the alternative domain (otherstore.com), use the default htaccess (when it is in root, otherwise add rewrite in htaccess)and put just this inside the index.php:

require __DIR__ . '/app/bootstrap.php';
$params = $_SERVER;
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'websitecode';
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('Magento\Framework\App\Http');

The following is key though, i did not get it to work otherwise, au contraire Magento 1 where we had lots of stores without this. Go to your other store root with ssh and enter this:

ln -s /path/to/your/install/public_html/m2/app/ app 
ln -s /path/to/your/install/public_html/m2/lib/ lib 
ln -s /path/to/your/install/public_html/m2/pub/ pub 
ln -s /path/to/your/install/public_html/m2/var/ var 

After we added the latter, everything seems to work fine, so far.

Good luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.