Welcome! Log In Create A New Profile

Advanced

rewrite N|next flag in apache

Posted by layneuks 
rewrite N|next flag in apache
January 05, 2012 10:58AM
Hi everyone,

I'm writing here because i have rewrite problems on Nginx. First of all i will explain to you what result i'm expecting.
For example i have this URL :

http://www.mydomain.com/api/redirect/var1/value1/var2/value2/varX/valueX/?varX=valueX&...

after rewrite i would like to get :

http://www.mydomain.com/?var1=value1&var2=value2&varX=valueX&varX=valueX...

So i get it works on apache with :

RewriteRule ^(api/redirect/[^\/]+/[^\/]+/[^\/]+)/([^\/]+)/([^\/]+)([^\?]*) $1$4/?&$2=$3 [QSA,N]
RewriteRule ^api/redirect/[^\/]+/[^\/]+/([^\/]+) index.php?service=Redirect&hash=$1 [QSA,L]

And now i would like to have the same on nginx, but i think nginx doesn't handle something like apache's N flag. Then it's my nginx rewrite rules, it work once because it doesn't re-execute rewrite while it's possible.

rewrite ^/(api/redirect/[^\/]+/[^\/]+/[^\/]+)/([^\/]+)/([^\/]+)([^\?]*) /$1$4/?&$2=$3;
rewrite ^/api/redirect/[^\/]+/[^\/]+/([^\/]+) /public/index.php?service=Redirect&func=Redirect&hash=$1 last;

Do someone have a solution for this please ? I will apreciate a lot. thanks you.

Best regards,
Re: rewrite N|next flag in apache
January 06, 2012 05:21AM
I believe the N flag is implied in nginx rules. Unless you put last or break at the end of the rule, it will keep matching. So the equivalent to the Apache rules you mention above is this:

rewrite ^/(api/redirect/[^\/]+/[^\/]+/[^\/]+)/([^\/]+)/([^\/]+)([^\?]*) /$1$4/?&$2=$3;
rewrite ^/api/redirect/[^\/]+/[^\/]+/([^\/]+) /index.php?service=Redirect&hash=$1 last;

You seem to have some extra stuff in the second rule ...
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 305
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready