Welcome! Log In Create A New Profile

Advanced

nginx rewrite rules conditional once again

Malte Geierhos
June 29, 2010 11:34AM
Hi List,

I've got to convert some Apache Rewrite Rules to work with nginx.
And i got kind of stuck in between how to solve this.

The old rewrite rule is like this :

RewriteCond %{REQUEST_URI} !/[0-9]+$
RewriteCond %{REQUEST_URI} ^/(articles|people)/favorites
RewriteRule ^(articles|people)/(.*)/$ /$1/$2/1/25 [R=301,L]

### /fragen/beliebte
RewriteCond %{REQUEST_URI} !/[0-9]+$
RewriteCond %{REQUEST_URI} ^/(articles|people)/favorites
RewriteRule ^(articles|people)/(.*) /$1/$2/1/25 [R=301,L]

so basically its catching those with ^/articles/favorites/what and
^/articles/favorites/
and append /1/25 and most important - ignore when there is already /2/40
or whatever.

At first i was looking into solving it with a location with something
like :

location ~* ^/(articles|people)([^/]*)$ {
rewrite ^/(articles|people)/(.*)$ /$1/$2/1/25;
}

but this did not work out as expected.
My next idea was to try to catch $2/$3 and see if its a number

like :

location ~* ^/(articles|people)/(.*)$ {
if ( $request_arg !~ [0-9]) {
rewrite ^/(articles|people)/(.*)$ /$1/$2/1/25;
}
}

hm but now i'm stuck.
Anyone got an idea ?

regards,
Malte


_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

nginx rewrite rules conditional once again

Malte Geierhos June 29, 2010 11:34AM

Re: nginx rewrite rules conditional once again

edogawaconan June 29, 2010 11:40AM

Re: nginx rewrite rules conditional once again

Igor Sysoev June 29, 2010 11:50AM

Re: nginx rewrite rules conditional once again

rahul286 June 30, 2010 06:20AM

Re: nginx rewrite rules conditional once again

Igor Sysoev June 30, 2010 06:26AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 228
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