Welcome! Log In Create A New Profile

Advanced

Re: location redirect always with trailing slash... sometimes

March 08, 2019 04:00AM
I found a solution (after reading the manual)
http://nginx.org/en/docs/http/ngx_http_rewrite_module.html
On Thu, 7 Mar 2019 at 14:57, Hans Schou <hsc@miracle.dk> wrote:

> 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
>

"rewrite" is the way to go.
To change /foo or /foo/ to /foo/ and don't change the rest, this will do it:
location ~ /(foo|bar) {
rewrite ^(/[^/]+)/? https://ex2.org$1/ permanent;
}

If any path should be handled this way:
location / {
rewrite ^(/[^/]+)/? https://ex2.org$1/ permanent;
}

--

Venlig hilsen - best regards
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

location redirect always with trailing slash... sometimes

hsc@miracle.dk March 07, 2019 08:58AM

Re: location redirect always with trailing slash... sometimes

hsc@miracle.dk March 08, 2019 04:00AM

Re: location redirect always with trailing slash... sometimes

Francis Daly March 11, 2019 05:04AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 313
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready