rewrite assistance

Francis Daly francis at
Wed Nov 24 13:43:40 MSK 2010

On Tue, Nov 23, 2010 at 11:42:38PM -0500, daveyfx wrote:

Hi there,

> > location = /preview.php {
> >   rewrite ^ /? permanent;
> > }

> Spot on.  That seems to have done the trick.  Out of my own desire to
> learn, is there a way to do the same thing without using the location
> directive, and just merely using a rewrite statement?


The manual says

syntax: rewrite regex replacement flag
default: none
context: server, location, if 

The location{} block just says "only try this for some urls".

Within the server{} block, it would be "try this for all urls", and only
urls that match the regex would be rewritten.

So: the "rewrite" line that was almost working for you, with the extra
bit on the replacement part to suppress adding the query string, should
be what you want.

Good luck,

Francis Daly        francis at

More information about the nginx mailing list