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.

Assuming a location block needs to handle URLs like

  • /test_api/group_1/version (several URLs fall in this group. For example, /test_api/aaa/version, /test_api/bbb/version)
  • /test_api/group_2/revision (several other URLs fall in this group. For example, /test_api/yyy/revision, /test_api/zzz/revision)

How can I selectively rewrite "/test_api/group_1/version" while passing "/test_api/group_2/revision" to a default server within a location block? If that's not possible, are there other ways to achieve the same goal. Below is my current non-discriminating location block.

location /test_api {
    types    { application/json json; }
    root     /usr/local/www/data;
    rewrite  "/test_api/([^/]+)/version(.*)/?$"   /api_response/test_api_$1.json   break;
}
share|improve this question
    
Might be better addressed in SuperUser SE –  mdpc Dec 20 '12 at 17:10
add comment

1 Answer

when you make two locations like

location /test_api/group_1/version {
  ...
}

location /test_api {
  ...
}

the LONGEST one will always match, so yours group_2 will not match 1st rule

share|improve this answer
    
Thanks for the suggestion. I have many URLs that fall in each group so I can't code it like that. I've updated the question to make it more clear. –  ytw Dec 20 '12 at 18:09
add comment

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.