Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have tried to rewrite the following Nginx locations rules to a single location block, but because of the (.*)$ it seems to be evading me..

 location ~ /admin {
    rewrite   ^/admin(.*)$ /target.php last;
 }

 location ~ /index/ {
    rewrite   ^/index/(.*)$ /target.php last;
 }

 location ~ /services/ {
    rewrite   ^/services/(.*)$ /target.php last;
 }

 location ~ /test/ {
    rewrite   ^/test/(.*)$ /target.php last;
 }

I have been able to use regex before, but couldn't get the approach below fit the above

 location ~ /(someplace|other|another) 
share|improve this question

1 Answer 1

up vote 1 down vote accepted

If always target.php (and where is $1? ):

location ~ /(test|services|index)/ {
    rewrite   ^/*/(.*)$ /target.php last;
}
share|improve this answer
    
Thanks. $1 gets ignored here because the FastCGI - which ultimately services the rewrite - uses $request_uri for onward decision making –  j pimmel Sep 23 '11 at 19:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.