Rewrite doesn't work if location has no trailing /

Reiner Bühl reiner at buehl.net
Sat Feb 9 10:50:22 UTC 2019


Hi all,

I currently use the following location to redirect every request for a 
resource under /webmail to a seperate server:

         location /webmail {
                 rewrite ^/webmail(.*) /$1 break;
                 proxy_pass http://127.0.0.1:8081;
                 proxy_redirect off;
                 proxy_set_header Host $host;
         }

This works fine for URLs like /webmail/ or /webmail/<*>. However if the 
URL is just /webmail - no trailing / - then the page itself is served 
from the other web server but all resources like pictures that are 
referenced in that page do not get rewriten. If I call the same page 
with /webmail/, all resources in the page are properly rewritten and 
load correctly.

Can you give me a hint what to change in the rule?

Best regards,
Reiner


More information about the nginx mailing list