Welcome! Log In Create A New Profile

Advanced

NGINX mangling rewrites when encoded URLs present

Posted by Bob Smith via nginx 
Bob Smith via nginx
NGINX mangling rewrites when encoded URLs present
May 05, 2018 01:30PM
nginx version: nginx/1.13.12

This is my rewrite:
location / {
rewrite ^/(.*)$ https://example.net/$1 permanent;
}

I am getting some really odd behavior.

For example:

mysubdomain.example.com/CL0/https:%2F%2Fapple.com

Gets re-written to

example.net/CLO/https:/apple.com

Only one forward-slash, not two before apple.com. The original declaration was %2F%2F ?_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Reinis Rozitis
RE: NGINX mangling rewrites when encoded URLs present
May 06, 2018 12:20AM
> rewrite ^/(.*)$ https://example.net/$1 permanent;
>
....
>
> Gets re-written to
>
> example.net/CLO/https:/apple.com
>
> Only one forward-slash, not two before apple.com. The original declaration was %2F%2F ?

It's probably because that way the $1 is/gets url-decoded and merge_slashes kicks in ( http://nginx.org/en/docs/http/ngx_http_core_module.html#merge_slashes ).

Try something like:

location / {
return 301 https://example.net$request_uri;
}

rr

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Sorry, only registered users may post in this forum.

Click here to login