Menu Close
    Hire us Request quote Reading list Switch to dark mode
    lockdownWebkulUp

    Multi Website Setup in Magento 2

    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.

    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.

    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.

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

    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

    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

    . . .
    Subscribe Articles

    Just enter your email below to subscribe and receive weekly updates about the most interesting similar articles.

    You need to accept conditions to receive letters.
    You've Subscribed!

    Share article via

    . . .

    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! 🙂

    . . .

    Comments (13)

    Add Your Comment

  • jaimin
    Good Post Really helpful to switch multiwebsites.
  • Adam
    Hi Shruti,
    Is there a need to create a sub-domain configuration on the server before pointing the sub-domain on Magento2 admin? My server is not identifying the sub-domain. (“Site cannot be reached”).

    Default is https://store.site.com
    Secondary is https://blah.site.com

    Thanks!

    • kajal sharma
      Yes, you need to configure the subdomain on the server first.
  • Jignesh
    Hello Shruti,

    suppose my website URL is https://www.example.com/us (us) is the website code.

    When I open the home page it will load properly but as soon as i will click on the category it will load main website URL https://www.example.com but instead of this it should redirect to https://www.example.com/us/category.html

    I have configured base URL and pub/static and /media URL on system > configuration.

    Base URL > https://www.example.com/us/
    Pub/Static URL > https://www.example.com/pub/static/
    Media URL > https://www.example.com/media/

    Any advice if anything i did wrong.

    Thanks

  • Faisal
    Can I create second website as a sub domain by using way?
    • Shruti Baranwal
      Yes. The steps I have mentioned here are for the Multi Website Setup using the subdomain. Please follow the steps and you’ll be able to create a new website using the subdomain. In case of any doubt please let me know.
      Thanks!
  • Sagar Patel
    I am trying to setup multi store in localhost so i has created website,store and store view also copied index.php and htaccess in new folder under root folder nut layout of site not look good.
    So can i copied all files from magento root to new folder?
    • Shruti Baranwal
      Hi,

      Have you created a new subdomain? In this process, you do not need to create any new folder or file. Please check the blog images that I have used 2 domains.
      Main Website-https://webkul.com/blog/wp-content/uploads/2018/04/3-9.png
      New Website-https://webkul.com/blog/wp-content/uploads/2018/04/5-6.png

      After completing magento web configurations the only thing you need to do is –
      Open the .htaccess file and just add 2 lines as mentioned here.

      In case of layout issues please run the following commands once-
      php bin/magento setup:static-content:deploy
      php bin/magento cache:flush

      If you are still facing any issue then please let me know.

      • dipak
        i created new website as above instruction but when run new website it is not working.
        • Shruti Baranwal
          Hi,
          Have you created a new subdomain? First, you need to check that your subdomain is working or not. Just hit your subdomain in the browser. If you are working on localhost then it will show you all the available folder of your path (/home/users/username/www/html/). If it’s showing then the above-mentioned process will work completely fine. Please check the steps correctly.
          Please let us know in case of any doubt.
          Thanks!
          • dipak
            yes i have created subdomain then need i create a subfolder in root dir.
          • Shruti Baranwal
            Hi,
            No, You don’t need to create any folder.
            Thanks!
  • Back to Top
    css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close