rewrite url segment staging site and live site

Francis Daly francis at
Thu Jun 14 21:16:42 UTC 2012

On Wed, Jun 13, 2012 at 10:31:02AM -0400, caleboconnell wrote:

Hi there,

you have a working set up now, so all is good.

But still, I am very surprised that

>   location /old {
>     rewrite ^/old/(.*)$ /new/$1 permanent;
>   }

will not cause a redirection for any request that starts /old/, when
replacing that location with

>   location /old {
>     rewrite ^/old? /new permanent;
>   }

will lead to the expected redirection.

The solution you found was to change the location definition to avoid
trying any regex locations. That suggests that you had other regex
locations which were being matched instead of the ones above. But
independent of that, the above two locations should redirect almost all
of the same requests (all bar exactly "/old") -- so if the rest of the
configuration didn't change in between the two tests, you have found
something odd.

> here is the current config, with prior rewrites before this location
> block:

For information: because one request is handled by one location, the
order of location blocks within the config file is not relevant (apart
from regex ones).

Which just means that "the most recent match" may not be from the location
block a few lines earlier in the config file.

All the best,

Francis Daly        francis at

More information about the nginx mailing list