I install the prestashop 1.7 as a multistore and write nginx rewrite rule as
location /shop-1/ {
rewrite ^/shop-1/(.*)$ /$1 last;
try_files $uri $uri/ /index.php?$args;
}
location /shop-2/ {
rewrite ^/shop-2/(.*)$ /$1 last;
try_files $uri $uri/ /index.php?$args;
}
I follow the nginx conf file from https://devdocs.prestashop.com/1.7/basics/installation/nginx/
Now the Q is Parent domain navigating correctly and showing images but multistore redirected corrected to http://example.com/{shop-1 or shop-2} but not showing the images on the multishop urls, getting nginx 404 error on multishop url but same image showing on a parent domain.
example:
http://example.com/shop-1/45-medium_default/skirt.jpg not showing the image
http://example.com/45-medium_default/skirt.jpg showing the image
To explain what happened here I need to refer to nginx request processing phases, a subject not many people actually understand correctly.
Here is a set of rewrite rules being executed at the
NGX_HTTP_SERVER_REWRITE_PHASE
:As you can see, none of them matches the
/shop-1/45-medium_default/skirt.jpg
request URI. So on the next turn, during theNGX_HTTP_FIND_CONFIG_PHASE
yourlocation /shop-1/ { ... }
will be selected to handle the request. Next, afterrewrite ^/shop-1/(.*)$ /$1 last;
rule being executed, your request URI will be rewritten to/45-medium_default/skirt.jpg
, and due to the usedlast
flag on therewrite
directive theNGX_HTTP_FIND_CONFIG_PHASE
will be executed again. However theNGX_HTTP_SERVER_REWRITE_PHASE
won't be executed again, and a new URI won't be rewritten according to those rules. What you should do instead is to place a rewrite rule at theserver
level before the ruleset for rewriting image requests:Note that I don't use
last
(orbreak
) flag for this rule since the rewrite rules chain should not be terminated after this rewrite will be triggered. None of those two locations that you show in your question will be needed at all.