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

    Create multiple websites in Magento2 and access them with different domains

    In this blog we will be learning how to create multiple websites in Magento2 and access them with different domains.

    The magento2 provides a functionality in which you can configure different websites from same magento instance. In this blog, we will see how to do the same!

    We will be mapping two domains i.e.

    https://www.myprimarydomain.com and
    https://www.mysecondarydomain.com

    1. Install the magento and configure the server normally for the main site https://www.myprimarydomain.com

    2. Now, create a new website, store and store view under Admin > Stores > Settings > All Stores

    3. Go To Admin > Stores > Settings > Configuration > General > Web

    4. This is the most important step as not selecting the secondary store, you can loose the access to the admin panel of the site.

    Select secondary store from the store configuration at the top:


    5. Configure the Base Url and the secure Base Url according to https://www.mysecondarydomain.com and save the config.

    6. Now create a sub-directory(any name, lets say it secondary) at the root of the magento2 installation.

    7. Copy the index.php and the .htaccess files from the root of the Magento2 to the sub folder.

    8. Replace the code in index.php:

    WITH


    And Code:

    WITH

    9. Now comes the role of the server management. You need to map the domain https://www.mysecondarydomain.com to /directory of magento installation/subfolder which we just created

    In my case it is: /var/www/html/secondary

    10. Now you need to create symlinks inside the new folder(secondary) to allow the secondary site access the CSS files and other static content.

    Execute the following commands using the terminal in the secondary folder:

    ln -s /home/example/example.com/html/app/ app

    ln -s /home/example/example.com/html/lib/ lib

    ln -s /home/example/example.com/html/pub/ pub

    ln -s /home/example/example.com/html/var/ var

    11. Clear Magento cache, generated, deploy static content at the root of the magento installation and check the site at https://www.mysecondarydomain.com

    . . .

    Comment

    Add Your Comment

    Be the first to comment.

    Back to Top
    css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just received your message and our expert will get back to you shortly.
    Send Again
    Close