Being one of the most powerful ecommerce platform in the industry, Magento boasts a stellar reputation because of its fluid functionality and secure infrastructure. And in this article we will discuss about how to configure multiple stores in Magento 2. So, we are all well-aware of the fact that there are many features which are launched by Magento from time to time. Multistore function is one of the features in Magento 2 which is for the merchants and developers. Magento 2 also provides you with the facility to setup multiple stores which you must have used in Magento 1 as well. But since we know that Magento 2 is absolutely different than the previous versions, it is a little difficult to manage features in it for those peoples who have just started doing development in Magento 2. This is because of the advancements that been made in the file system. So, without further ado, I’ll teach you the complete store configuration in Magento 2, so that you can further configure multiple stores in Magento 2 like a boss:
When you want to create a second store in Magento 2, you have to go to the Admin dashboard of your Magento 2 store and from there follow this path Stores/ Settings / All Stores
<?php $params = $_SERVER; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'yourcode.yourdomain.com'; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website'; $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params); $app = $bootstrap->createApplication('Magento\Framework\App\Http'); $bootstrap->run($app); ?>
Now make sure you Save your index.php file. After doing this you have to set the values in .htaccess file. This section here discusses the process through which you can set values for MAGE_RUN_TYPE and MAGE_RUN_CODE for using Apache Server Variables SetEnvIf or RewriteCond. To setup SetEnvIf, you have to add the following in your .htaccess file after “RewriteEngine on” this:
SetEnvIf Host .*example.com.* MAGE_RUN_CODE=yourcode.yourdomain.com SetEnvIf Host .*example.com.* MAGE_RUN_TYPE=website
To setting up RewriteCond, you should add the following code in your .htaccess file after “RewriteBase /magento/” This:
RewriteCond %{HTTP_HOST} ^(.*)example\.com RewriteRule .* – [E=MAGE_RUN_CODE:yourcode.yourdomain.com] RewriteCond %{HTTP_HOST} ^(.*)example\.com RewriteRule .* – [E=MAGE_RUN_TYPE:website]
Now again Save your .htaccess file.
Congratulations! Now you have successfully configured multiple stores in Magento 2 and you can get started with it. I suggest since you’ve worked so hard configuring it, it’s integral that you host it on a secure and best ecommerce hosting platform. So that you get the best security, and your cart’s abandonment ratio remains below the danger zone at all times. So, let us know which hosting platform you are using for your ecommerce business in the comment section below and if you’re satisfied with it.