Magento Multistore Website Configuration
This article will explain how to configure your Magento store to use as Magento Multistore Website.
For explanation purpose, I’ll use two domain setup. You can use the same structure to create more websites for your Magento Multistore Website.
Magento Multistore Stores Setup
First step to configure your Magento Multistore site, is to add two websites for your domains. Login to your administrator panel and go to
Stores -> Settings -> All Stores
Let’s look at each of three options
Web site
We need to focus on web site section of all stores. In default Magento comes with one web site (base). If you need more domains you need to create more web sites.
Websites not sharing cart, user sessions, payment gateways, shipping etc.
Store
Each website have at lease one store. Stores share cart, payment gateways etc.
Typically used in different product selections, menu structure etc.
Store View
Stores can have one or several store views. Store views typically used in layouts and lanugages
Click on Create Website. Create New website and note the code.

For my article I’ll use my base web site for first domain and Australian Web Site for second domain.

Configuration Two Domains
Next step is to configure our domains for our Magento site. Go to Stores -> Configuration -> Web -> General tab
Setup your Base URLs and Base URLs (secure) to your default site, I’ve use multisite.fc5.forge.co.nz as our default store front.

While you still in Stores -> Configuration, Select Australian web site from Store view on top of the configuration page.

Change Base URLs and Base URLs (secure) to your second web site(australian.fc5.forge.co.nz).

Bootstrapping your Magento Multistore
Open your index.php file and replace following line.
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $server);
With following 4 lines of code
$params = $_SERVER; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'base'; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website'; $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
Note:
If you have install mod_rewrite make sure enviorenment vairables are not prepending. If that is the case in your index page use as follows
$params = $_SERVER; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = $_SERVER["REDIRECT_MAGE_RUN_CODE"]; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = $_SERVER["REDIRECT_MAGE_RUN_TYPE"]; $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
.htaccess changes
Open your root .htaccess file and add following lines
SetEnvIf Host .*multidomain.fc5.forge.co.nz.* MAGE_RUN_CODE=base SetEnvIf Host .*multidomain.fc5.forge.co.nz.* MAGE_RUN_TYPE=website SetEnvIf Host .*australian.fc5.forge.co.nz.* MAGE_RUN_CODE=australia SetEnvIf Host .*australian.fc5.forge.co.nz.* MAGE_RUN_TYPE=website
below
# SetEnv MAGE_MODE developer
Make sure to use correct MAGE_RUN_CODE for given url.
Go to #RewriteBase /magento/ and include following lines of code
RewriteCond %{HTTP_HOST} ^(.*)multidomain\.fc5\.forge\.co\.nz
RewriteRule .* – [E=MAGE_RUN_CODE:base]
RewriteCond %{HTTP_HOST} ^(.*)multidomain\.fc5\.forge\.co\.nz
RewriteRule .* – [E=MAGE_RUN_TYPE:website]</code>
RewriteCond %{HTTP_HOST} ^(.*)australian\.fc5\.forge\.co\.nz
RewriteRule .* – [E=MAGE_RUN_CODE:australia]
RewriteCond %{HTTP_HOST} ^(.*)australian\.fc5\.forge\.co\.nz
RewriteRule .* – [E=MAGE_RUN_TYPE:website]
Due to spamming we are not allow comment in this article. However if you have any Questions or Queries please send to nuwinda(at)forgeonline(dot)co(dot)nz. For more information please refer Magento documentation .


