Magento has the solution by default but the project should is in the root but if your project is in a sub-folder then you will have a problem recognizing the code new websites.
For Apache the solution is an index.php and .htaccess but if you using Nginx then follow the next steps:
- Create root categories
- Create websites
- Create stores
- Create store views
- Add the store code to the base URL
- In the Admin panel, click
Stores > Settings > Configuration > General > Web
. - In the right pane, expand
Url Options
. - Clear the
Use system value
checkbox next to Add Store Code to Urls. - From the Add Store Code to Urls list, click
Yes
. - Click Save Config.
- If prompted, flush the Magento cache. (System > Cache Management).
For the details steps mentioned you can check this articule. https://devdocs.magento.com/guides/v2.3/config-guide/multi-site/ms_websites.html
- Finally we need define the code website per URL segment.
- Create a map in your domain.conf
/etc/nginx/conf.d/website.conf
.
map $http_host $MAGE_RUN_CODE {
dev.mywebsite.com base;
}
map $http_host$uri $MAGE_RUN_CODE {
~*^(dev\.)?mywebsite\.com/website1/.* website1;
~*^(dev\.)?mywebsite\.com/website2/.* website2;
}
or
map $request_uri $MAGE_RUN_CODE {
default default;
~^/website1/.* website1;
~^/website2/.* website2;
}
- sudo service nginx restart