Url rewriting faliure in case of UTF8 urls

I want to rewrite some old urls on my site to new ones inorder to
prevent
404 errors. For English urls everything is OK and adding a rewrite rule
like
the following to the server block works fine.

rewrite ^/omid/$ /omidreza;

But when it comes to urls containing non-English characters the rule
doesn`t
work. Has anyone experienced the same issue?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,245202,245202#msg-245202

On Wed, Dec 04, 2013 at 08:22:42AM -0500, omidr wrote:

Hi there,

But when it comes to urls containing non-English characters the rule doesn`t
work. Has anyone experienced the same issue?

It seems to work for me.

What config do you use, what request do you make, what response do you
get?

f

Francis D. [email protected]

As an example I want to redirect “/آرایشگر” to “/استخدام آرایشگر” and I
am
using a rewrite rulr like the one below but things go wrong and I get a
404.

rewrite_rule: rewrite ^/آرایشگر/$ /استخدام آرایشگر;

And what do you mean by config? Do you mean nginx settings or
configurations
at compile time?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,245202,245225#msg-245225

On Wed, Dec 04, 2013 at 07:42:17PM -0500, omidr wrote:

Hi there,

As an example I want to redirect “/آرایشگر” to “/استخدام آرایشگر” and I am
using a rewrite rulr like the one below but things go wrong and I get a
404.

Can I suggest you try to simplify the test case, so that you can see
what exactly is happening?

Use “rewrite A B permanent;”, and if the url matches A you will see a
redirection to B in the http response headers; and if it does not match
A you will not see a redirection to B.

That way you will know whether the request that you made matched this
rewrite or not.

What matters to nginx are the actual bytes written inside the config
file,
and the actual bytes received in the request.

rewrite_rule: rewrite ^/آرایشگر/$ /استخدام آرایشگر;

So, make that be (say)

rewrite ^/گر$ /match-گر permanent;

and then do something like

grep permanent nginx.conf | xxd

so that you can see the bytes that are in the file on that line.

Then issue your single request for /گر, and watch the http response –
do you get the permanent redirect, or something else?

It is probably worth watching the network traffic using tcpdump, or some
other means, so that you can see what bytes are sent by the browser. If
the rewrite doesn’t match when you think it should, the tcpdump output
might give an indication of why that was.

And what do you mean by config? Do you mean nginx settings or configurations
at compile time?

I mean “enough information so that it is easy for me (or anyone else)
to do what you are doing so as to be able to see the problem that you
are reporting”.

I first tested using a line

rewrite ^/omíd/$ /omídreza permanent;

where the character between “om” and “d” is the two bytes c3 ad, which
is the utf-8 representation of “LATIN SMALL LETTER I WITH ACUTE”

I tested using “curl -i” asking for /omíd/ and also /om%C3%ADd/. I saw
the expected redirection.

So nginx is correctly handling a rewrite of a UTF8 url.

Can you test with that same thing, and see if your nginx responds
differently? If it does respond differently, then there is something
significant different between my nginx and your nginx, so the “nginx -V”
output will probably matter.

f

Francis D. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs