How to Set Up a Magento 2 Multistores?

Harpreet Singh June 10, 2019

How to Set Up a Magento 2 Multistores?

In this write-up, I’ll explain the process to set up multiple stores with different domains in Magento2.

Here is the detailed process:

Step 1: Create a new website & set up a store and a store view that is needed for the new website.

a) Go to Stores > Settings > All Stores & click on the “Create Website” button to create a new website.

Fill the website information and save the website as illustrated below:

b) After that to create a new store, click on the “Create Store” button

Fill in the store information & save store:

c) Now to create a store view, click on the “Create Store View” button shown below:

Fill store view information & save store view:

Step 2: Configure the Store URL:

Go to Stores > Configuration & Select Store View:

I created a German website, German website store & German store view as shown in the above screenshot.

Under the General section click on Web.

Expand Base URLs & Base URLs (Secure) section and Enter this website’s URL. For example https://subdomain.example.com/

Flush the Magento cache. (System > Cache Management).

After that, you need to modify index.php

$params = $_SERVER;$domain2store = array(
    'german.example.com'=>'de_website', // Replace your Website, Store or Storeview code with this.
    );
if(isset($domain2store[$_SERVER['HTTP_HOST']]))
    $storecode = $domain2store[$_SERVER['HTTP_HOST']];
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = isset($storecode) ? $storecode : '';
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);

Found the article interesting? Share it with your friends… Now!

Lets’s Talk

About your ideas and concept