Magento 2.1 Multi-Store Setup on Different Domains

magento-2.1multistore

I have created a sub-website, sub-store, and sub-store-view from magento2 admin and update sub-store base url from configuration setting.

After that I have created a subdomain (sub.example.com), but here I am little confused that subdomain will link to root directory or any sub directory, and what changes I have to make in index.php and .htaccess file?

Best Answer

I have created successfully sub website in magento2, steps are as follows :

1) Create "Sub Website/Sub Store/ Sub Store View" from admin panel.

2) Update configuration setting :

base Url (http://sub.example.com/)
Link Url (http://sub.example.com/)
Static Url (http://example.com/pub/static/)
Media Url (http://example.com/pub/media/)

3) Create a sub directory 'sub' in magento root directory and point "sub domain (sub.example.com)" to this directory.

4) Copy index.php and .htaccess to this directory from root and made two changes in index.php

i) replace "/app/bootstrap.php" to "/../app/bootstrap.php"

ii) replace
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER); 

to 

$params = $_SERVER;$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = "sub";
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = "website"; 
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);