This article will help you to understand how one can add multiple websites in Magento 2.
Magento allows you to setup multi-websites on just single installation of Magento. Its configuration is straightforward. It will allow you to create a separate website so you can handle the products, customers, product price and many more things on websites bases.
After installing Magento you need to login into the store and follow the steps given below:
Stores>Settings>All Stores and create a new website, a new store and a new store view.
This is just the sample data. For instance, we have named our website as German website. After saving this information you will find it in the list as shown below.
Stores>Configuration>General>Web>Base URLs, here you need to update the Base Url and Base link URL fields.
Stores>Configuration>General>Web>Base URLs (Secure), here you will see that the Base Url and Base link URL fields will be automatically filled.
This image shows the base URL section with the required domain name.
The above screenshot shows the secure area of base URLs with their required domain name.
We need to update these URLs for the German website. You will see a store view option at the top of the page on the left side. Open this drop-down menu and select German website.
Save this configuration.
Now we need to open the file
.htaccess from our Magento root directory. And find IfModule mod_rewrite.c section. Add below lines of code in this section.
SetEnvIf Host magentogerman.com* MAGE_RUN_CODE=german_website
SetEnvIf Host magentogerman.com* MAGE_RUN_TYPE=website
Now we will be able to access both our websites.