Welcome! Log In Create A New Profile

Advanced

Re: Strange behaviour of %27 encoding in rewrite

aquilinux
November 19, 2018 11:40AM
Thanks Maxim, using the return directive worked flawlessly.

Regards,

On Thu, Nov 15, 2018 at 4:55 PM Maxim Dounin <mdounin@mdounin.ru> wrote:

> Hello!
>
> On Wed, Nov 14, 2018 at 03:54:20PM +0100, aquilinux wrote:
>
> > Hi all,
> > i'm seeing a strange behaviour in nginx rewrite involving encoded urls
> for
> > *%27*
> > I have this type of rewrite:
> >
> > rewrite "^/brands/l-oreal$"
> > > https://somedomain.tld/L%27Or%C3%A9al-Paris/index.html? permanent;
> > >
> >
> > That translates to this:
> >
> >
> > > [~]> curl -kIL https://mydomain.tld/brands/l-oreal
> > > HTTP/2 301
> > > server: nginx
> > > date: Wed, 14 Nov 2018 14:44:21 GMT
> > > content-type: text/html
> > > content-length: 178
> > > *location: https://somedomain.tld/L'Or%C3%A9al-Paris/index.html
> > > https://somedomain.tld/L'Or%C3%A9al-Paris/index.html*
> > > strict-transport-security: max-age=15768000; includeSubDomains
> >
> >
> > If i change %27 to %20 i have:
> >
> > [~]> curl -kIL https://mydomain.tld/brands/l-oreal
> > > HTTP/2 301
> > > server: nginx
> > > date: Wed, 14 Nov 2018 14:31:09 GMT
> > > content-type: text/html
> > > content-length: 178
> > > *location: https://somedomain.tld/L%20Or%C3%A9al-Paris/index.html
> > > https://somedomain.tld/L%20Or%C3%A9al-Paris/index.html*
> > > strict-transport-security: max-age=15768000; includeSubDomains
> >
> >
> > as expected.
> >
> > The same strange behaviour applies to *%2C*, that is decoded to "*,*"
> > instead of being passed unencoded, as expected.
> > This is driving me nuts, can anyone explain (or fix) this?
>
> This is because both "'" and "," don't need to be escaped.
>
> And, given that the rewrite directive operates on the internal URI
> representation, the replacement argument is unescaped by nginx,
> and then escaped again when returning a permantent redirect. But
> it only escapes characters which need to be escaped.
>
> If you want nginx to return a redirect exactly in the way you
> wrote it, please consider using the "return" directive instead,
> for example:
>
> location = /brands/l-oreal {
> return 301 https://somedomain.tld/L%27Or%C3%A9al-Paris/index.html;
> }
>
> --
> Maxim Dounin
> http://mdounin.ru/
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>


--
"Madness, like small fish, runs in hosts, in vast numbers of instances."

Nessuno mi pettina bene come il vento.
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Strange behaviour of %27 encoding in rewrite

aquilinux November 14, 2018 09:56AM

Re: Strange behaviour of %27 encoding in rewrite

Maxim Dounin November 15, 2018 10:56AM

Re: Strange behaviour of %27 encoding in rewrite

aquilinux November 19, 2018 11:40AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 72
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready