Redirect on $args based on multiple params?

Phillip B Oldham phill at theactivitypeople.co.uk
Wed Mar 25 18:55:02 MSK 2009


Is there any way to capture multiple parameters from a querystring for a 
rewrite?

For example:
The request is: /myscript.php?a=b&c=d&z=y
The target is: /script/a/b/c/d/z/y

So, the basic rewrite would be:

location /myscript.php {
if( $args ~* ^a=([^\&]+)&b=([^\&]+)&z=([^\&]+)$ ){
rewrite ^ /script/a/$1/b/$2/z/$3 permanent;
}
}

However, how would I cope with situations where the args aren't in the 
order of a/b/z? Obviously if I have 10 args I don't want to have to do 
an "if" for each permutation, that could get both confusing and lengthy!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: phill.vcf
Type: text/x-vcard
Size: 261 bytes
Desc: not available
URL: <http://nginx.org/pipermail/nginx/attachments/20090325/0b0d5a5e/attachment.vcf>


More information about the nginx mailing list