Back to Top

Multi Website Setup in Magento 2

Updated 26 June 2019

Magento allows you to setup multi-websites for your single installed Magento. Its configuration is really simple which I’ll explain later. It will allow you to create a separate website and the real benefits are you can handle your products, customers, product price and may more things website wise. You can use these global or website wise depends on your needs.

You must have 2 different domains to setup multi-websites. like- www.magentotest1.com & test.magentotest1.com.

The first thing you need to do is log in to your Magento. Then follow the following steps-

  1. Navigate to Stores>Settings>All Stores and create a new website than a new store and a new store view. you can use an already created store and store view the main thing you need to create is a new website.

stores

stores language

Searching for an experienced
Magento 2 Company ?
Find out More

2. Navigate to Stores>SettingsConfiguration>General>Web>Base URLs, here Base Url and Base link URL fields will be automatically filled.

Navigate to Stores>SettingsConfiguration>General>Web>Base URLs (Secure), here Base Url and Base link URL fields will be automatically filled.

Base URl

3. Now you need to update these URLs for your newly created website. You’ll see a store view option on the top of the page on the left side. Open this drop-down and select your newly created website.

Configuration

4. Now update the Base URL & Base Link URL fields in Base URLs and Base URLs (Secure). Save this configuration now.

SEO

Base URLs(secure)

5. Now you need to open the .htaccess file from your Magento root directory and search for the “## enable rewrites” and add the following lines and save it.

SetEnvIf Host test.magentotest1.com* MAGE_RUN_CODE=french_website
SetEnvIf Host test.magentotest1.com* MAGE_RUN_TYPE=website

Enable rewrites

Now you can access both the websites.

SERVER CONFIGURATION:

WildCard DNS Entry With Apache and Nginx Web Servers for Global :

In order to create a wildcard domain for global access, we need to create wildcard entry (A entry in our case) for domains on DNS server ex: *.example.com or *.test.example.com along with the base domain entry (example.com). So that it will recognize all the traffic for DNS i.e. test.example.com with *.test.example.com and route it configured the domain.

WildCard Entry with Apache Web Server:

For the same with an apache web server, we need to configure on apache config file inside /etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>

#ServerName www.example.com

ServerAdmin webmaster@localhost

DocumentRoot /var/www/html

</VirtualHost>

Edit above, uncomment ServerName and replace your required domain name with www.example.com and add ServerAlias with *.domain name as below:

<VirtualHost *:80>

ServerName test.webkul.com

ServerAlias *.test.webkul.com

ServerAdmin webmaster@localhost

DocumentRoot /var/www/html

</VirtualHost>

WildCard Entry with Nginx Web Server:

With nginx, we need to change in nginx config file within server configuration i.e. in /etc/nginx/sites-available/default

server {

listen 80 default_server;

listen [::]:80 default_server;

root /var/www/html;

# Add index.php to the list if you are using PHP

index index.html index.htm index.nginx-debian.html;

server_name _;

}

here, replace underscore (_) with domain_name and *.domain_name as:

server {

listen 80 default_server;

listen [::]:80 default_server;

root /var/www/html;

# Add index.php to the list if you are using PHP

index index.html index.htm index.nginx-debian.html;

server_name test.webkul.com *.test.webkul.com;

}

If you are looking for a quick Magento 2 installation? Please visit our blog Shell/Bash Script to Install Magento 2

Hope it will help you. Still, have any doubt then please leave a comment here.

Thanks! 🙂

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


13 comments

  • jaimin
  • Adam
    • kajal sharma (Moderator)
  • Jignesh
    • Shruti Baranwal (Moderator)
  • Faisal
    • Shruti Baranwal (Moderator)
  • Sagar Patel
    • Shruti Baranwal (Moderator)
      • dipak
        • Shruti Baranwal (Moderator)
          • dipak
          • Shruti Baranwal (Moderator)
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home