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-
- 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
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! 🙂
13 comments
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!
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
The process which is mentioned above is to setup a megonto with 2 domains. For which you must have 2 domains like- https://www.example.com/ and https://www.test.com/.
Thanks!
Thanks!
So can i copied all files from magento root to new folder?
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.
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!
No, You don’t need to create any folder.
Thanks!