3

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:

https://example.com/uk/

https://example.com/ny/

https://example.com/chengdu/en

https://example.com/chendgu/cn

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.

Thanks

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 at 9:38
1

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

https://community.magento.com/t5/Magento-2-x-Admin-Configuration/Magento-2-Multi-website-single-domain-configuration/td-p/94275

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');
$bootstrap->run($app);

But with a switch statement looking at hostname

$_SERVER['SERVER_NAME']

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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