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

We're transitioning from a set of locations of the form: where we will do a redirect to /app2.

However, we want to keep some URIs for app1 active, e.g., and should NOT redirect.

How should this be done? The location block doesn't accept a prefix like "!~", which would make it easy, i.e.,

location !~ /app1/(111|222) {
  rewrite /app1 /app2;

does not work in terms of the location pattern matching.

I've tried this (as well as putting parens around everything after /app1/), but it doesn't work either:

location ~ /app1/!(111|222) {
  rewrite /app1 /app2;


share|improve this question
up vote 1 down vote accepted

cmiiw could you try (pls make sure the order is correct, and you may try to change the regex)

location ~ ^/app1/111$ {

location ~ ^/app1/222$ {

location ~ ^/app1$ {
  rewrite /app1 /app2;
share|improve this answer
My simple example is to simple; I had to add a bunch of proxy-type statements into the "location ~ ^/app1/(111|222}" block. I believed I missed one of them in an earlier test. – cjc Jan 30 '12 at 18:57

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.