Forum: NGINX redirect question (inception inside)

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ronald Van Assche (Guest)
on 2014-08-16 10:27
(Received via mailing list)
I want to redirect /us/us/directory/filename to the
/us/directory/filename directory on my Nginx server.

but this

        if ( $request_filename ~ /us/us/.+ ) {
                rewrite ^(.*) http://mysiteurlt/us/$1 permanent;

wont work.

How can i redirect or rewrite such url  ?
itpp2012 (Guest)
on 2014-08-16 10:44
(Received via mailing list)
Shouldn't the /us/ be removed in the rewrite? what does the logfile say
where it is trying to locate to?

Posted at Nginx Forum:,252606,252607#msg-252607
Edho Arief (Guest)
on 2014-08-16 10:53
(Received via mailing list)
On Sat, Aug 16, 2014 at 5:27 PM, Ronald Van Assche <>
> How can i redirect or rewrite such url  ?
location ^~ /us/us/ {
  rewrite ^/us(/us/.*) $1 permanent;
Ronald Van Assche (Guest)
on 2014-08-16 11:23
(Received via mailing list)
NICE : it works

more complicated one :

/ue//ue/data/filename => /ue/data/filenam
there is 2 / in the URL.

 location ^~ /ue//ue/ {
                rewrite ^/ue(/ue/.*) $1 permanent;

does not work :o(

Le 16 aot 2014  10:52, Edho Arief <> a crit :
Edho Arief (Guest)
on 2014-08-16 12:08
(Received via mailing list)
On Aug 16, 2014 6:22 PM, "Ronald Van Assche" <> wrote:
>         }
> does not work :o(

try reading the documentation:
Ronald Van Assche (Guest)
on 2014-08-16 12:27
(Received via mailing list)
YEP thank you :
> The matching is performed against a normalized URI, after decoding the text
encoded in the %XX form, resolving references to relative path components . and
.., and possible compression of two or more adjacent slashes into a single 

so i do not have to put // in the location , and it works

   location ^~ /ue/ue/ {
                rewrite ^/ue(/ue/.*) $1 permanent;

Thank you all people here.


Le 16 aot 2014  12:07, Edho Arief <> a crit :
This topic is locked and can not be replied to.