We are trying to set up a new Magento 2.3 instance to have multiple websites under a single domain.

I have read most of the posts based on this situation, but most either talk about multiple domain or using apache and therefore .htaccess.

We are using nginx and the default .conf that is given by Magento base install.

Our client has multiple locations based on countries e.g. UK, NY, Chengdu and each location has multiple languages. For this reason we would like to set up the locations as websites and the URL structure to be:





We have set up the websites with the correct store views.

We have set the based URL's on a website level to the same as above.

I have tried to created directories in /pub for the locations and copied in the index.php.

I have tried setting the MAGE_RUN_* codes in nginx.

But the closest I have got to getting this working is every page under a website (/uk) 404'ing.

What I am asking for is if someone could point me in the right direction to the correct nginx configuration to make websites work like this without 404ing?

The structure has to be like this and not under different domains or subdomains.



2 Answers 2


I think you have tried to find the solution from the google but my advise is to check Magento DevDocs first always where you can find everything which can be done in Magento 2. Here, I have attached the link where Magento DevDocs provided the steps to setup the multiple websites or stores.

Kindly refer this link: https://devdocs.magento.com/guides/v2.3/config-guide/multi-site/ms_over.html

So in the documentation, You will find how to setup the multiple websites or stores with Ngnix as well.

  • Thanks for the response, I have looked through this and is one of the implementations I have tried, but this specifically uses different domains, so does not work for subdirectories instead.
    – Tom Burman
    Jun 27, 2019 at 9:38

Have you considered editing index.php to catch php server host and then loading store view based on this. So no nginx rules. Hardcoded logic within magento itself. We had a problem install where we just couldn't multisite working and this worked for us.

So like this


Just this part

$params = $_SERVER;
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'uk'; //Webite code as same in admin panel
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('Magento\Framework\App\Http');

But with a switch statement looking at hostname


  • Hi Dominic, thanks for the response, yes I have tried this but consistently returns 404 when visiting example.com/uk
    – Tom Burman
    Jun 27, 2019 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.