1

I'm trying to create an store language, and use a path on main domain to server that store. To do it I've already done all the nginx magic to made it select the correct store, but my problem is that store is giving 404 on all pages.

Now on my magento I have two stores:

https://example1.com/
https://example2.com/

The content managers has created a language store on https://pt.example2.com/ that seems to works, but now they want to move that subdmain to a path, so I've changed the Stores > Configuration > General > web to https://example2.com/pt/ and I've configured the Nginx to send the MAGE_RUN_CODE and MAGE_RUN_TYPE to Magento.

My problem is that all was working at the subdomain, but now in path I can see how the language changes to that store language, but everything gives me a 404 error (even the 404 page gives me an error saying that there's no 404 page configured).

I've tried everything I've found on internet, clearing cache, reindexing all, setup:upgrade in combination with cache clearing and reindexing,... trying to remove the path using nginx rewrites, remove the path from fastcgi_param REQUEST_URI (this creates a loop because the store detects that is not its main page and tries to redirect), but nothing works.

Someone knows how to fix this problem?

Thanks!

0

Finally I got it fixed thanks to this post: Magento 2: How to configure Nginx to use multiple websites with sub-folder

As I am already passing the store using the Nginx MAGE_RUN_CODE variable, so I have not used the PARAM_RUN_CODE and PARAM_RUN_TYPE lines. Also the nginx.conf was failing for me, so I've removed the root entry.

Steps:

cd /var/www/magento/pub
mkdir pt
cp index.php pt/

changes on index.php:

require __DIR__ . '/../app/bootstrap.php';

to:
require __DIR__ . '/../../app/bootstrap.php';

Add to nginx.conf.sample of /var/www/magento/:

location /pt {
    if (!-e $request_filename) {
        rewrite ^/(.*)$ /pt/index.php last;
        break;
    }
}

Change the "PHP entry point for main application" to include your new path:

location ~ ^/(index|get|static|errors/report|errors/404|errors/503|health_check)\.php$ {

to:
location ~ ^/(pt\/)?(index|get|static|errors/report|errors/404|errors/503|health_check)\.php$ {

If still failing, try to move the added nginx.conf.sample entry to above the last deny location:

location /pt {
    if (!-e $request_filename) {
        rewrite ^/(.*)$ /pt/index.php last;
        break;
    }
}

# Banned locations (only reached if the earlier PHP entry point regexes don't match)
location ~* (\.php$|\.phtml$|\.htaccess$|\.git) {
    deny all;
}

Best regards

EDIT: Now with it working, I have done some tests and I've found that is better to link the pub folder to subdir directly, because that helps to fix 404 errors on statics and media (also you can configure those files to be loaded from /).

Link the pub folder to new store folder:

cd /var/www/magento/pub
ln -s . pt

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.