location redirect always with trailing slash... sometimes

Hans Schou hsc at miracle.dk
Thu Mar 7 13:57:40 UTC 2019


I have this buggy backend application where I try to let Nginx sort out the

Example of required redirect:
http://ex.org/foo -> https://ex2.org/foo/    # Nx solves the bug here
http://ex.org/foo/ -> https://ex2.org/foo/
http://ex.org/foo/?id=7 -> https://ex2.org/?id=7

Here is my current configuration which is in too parts but I have the idea
that I'm doing it wrong and it can be done in only one "location" with a

    location ~ /foo$ {
        return 301 https://ex2.org$request_uri/;
    location ~ /foo/$ {
        return 301 https://ex2.org$request_uri;

I have several paths like /foo/ where I would like to have them all in one
regex like
  location ~ /(foo|bar)/$ {


Venlig hilsen - best regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20190307/c9c86cc8/attachment.html>

More information about the nginx mailing list