<div dir="ltr">Thanks Maxim, using the return directive worked flawlessly.<div><br></div><div>Regards,</div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Nov 15, 2018 at 4:55 PM Maxim Dounin <<a href="mailto:mdounin@mdounin.ru">mdounin@mdounin.ru</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello!<br>
<br>
On Wed, Nov 14, 2018 at 03:54:20PM +0100, aquilinux wrote:<br>
<br>
> Hi all,<br>
> i'm seeing a strange behaviour in nginx rewrite involving encoded urls for<br>
> *%27*<br>
> I have this type of rewrite:<br>
> <br>
> rewrite "^/brands/l-oreal$"<br>
> > <a href="https://somedomain.tld/L%27Or%C3%A9al-Paris/index.html" rel="noreferrer" target="_blank">https://somedomain.tld/L%27Or%C3%A9al-Paris/index.html</a>? permanent;<br>
> ><br>
> <br>
> That translates to this:<br>
> <br>
> <br>
> > [~]> curl -kIL <a href="https://mydomain.tld/brands/l-oreal" rel="noreferrer" target="_blank">https://mydomain.tld/brands/l-oreal</a><br>
> > HTTP/2 301<br>
> > server: nginx<br>
> > date: Wed, 14 Nov 2018 14:44:21 GMT<br>
> > content-type: text/html<br>
> > content-length: 178<br>
> > *location: <a href="https://somedomain.tld/L'Or%C3%A9al-Paris/index.html" rel="noreferrer" target="_blank">https://somedomain.tld/L'Or%C3%A9al-Paris/index.html</a><br>
> > <<a href="https://somedomain.tld/L'Or%C3%A9al-Paris/index.html" rel="noreferrer" target="_blank">https://somedomain.tld/L'Or%C3%A9al-Paris/index.html</a>>*<br>
> > strict-transport-security: max-age=15768000; includeSubDomains<br>
> <br>
> <br>
> If i change %27 to %20 i have:<br>
> <br>
> [~]> curl -kIL <a href="https://mydomain.tld/brands/l-oreal" rel="noreferrer" target="_blank">https://mydomain.tld/brands/l-oreal</a><br>
> > HTTP/2 301<br>
> > server: nginx<br>
> > date: Wed, 14 Nov 2018 14:31:09 GMT<br>
> > content-type: text/html<br>
> > content-length: 178<br>
> > *location: <a href="https://somedomain.tld/L%20Or%C3%A9al-Paris/index.html" rel="noreferrer" target="_blank">https://somedomain.tld/L%20Or%C3%A9al-Paris/index.html</a><br>
> > <<a href="https://somedomain.tld/L%20Or%C3%A9al-Paris/index.html" rel="noreferrer" target="_blank">https://somedomain.tld/L%20Or%C3%A9al-Paris/index.html</a>>*<br>
> > strict-transport-security: max-age=15768000; includeSubDomains<br>
> <br>
> <br>
> as expected.<br>
> <br>
> The same strange behaviour applies to *%2C*, that is decoded to "*,*"<br>
> instead of being passed unencoded, as expected.<br>
> This is driving me nuts, can anyone explain (or fix) this?<br>
<br>
This is because both "'" and "," don't need to be escaped.<br>
<br>
And, given that the rewrite directive operates on the internal URI <br>
representation, the replacement argument is unescaped by nginx, <br>
and then escaped again when returning a permantent redirect. But <br>
it only escapes characters which need to be escaped.<br>
<br>
If you want nginx to return a redirect exactly in the way you <br>
wrote it, please consider using the "return" directive instead, <br>
for example:<br>
<br>
location = /brands/l-oreal {<br>
return 301 <a href="https://somedomain.tld/L%27Or%C3%A9al-Paris/index.html" rel="noreferrer" target="_blank">https://somedomain.tld/L%27Or%C3%A9al-Paris/index.html</a>;<br>
}<br>
<br>
-- <br>
Maxim Dounin<br>
<a href="http://mdounin.ru/" rel="noreferrer" target="_blank">http://mdounin.ru/</a><br>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org" target="_blank">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" rel="noreferrer" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">"Madness, like small fish, runs in hosts, in vast numbers of instances."<div><br></div><div><div>Nessuno mi pettina bene come il vento.</div></div></div></div>