Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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


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.