rewrite assistance

Francis Daly francis at daoine.org
Wed Nov 24 03:28:26 MSK 2010


On Tue, Nov 23, 2010 at 04:41:04PM -0500, daveyfx wrote:

Hi there,

> I'm trying to add in a rewrite rule that will take this string and just
> do a redirect to /
> /preview.php?controllerName=channel&id=2

http://wiki.nginx.org/HttpRewriteModule is worth reading.

> Since the query string can vary, how would I craft my rewrite
> appropriately to do this?  I've tried a few variations of the following,
> but all it does is remove the "preview.php" portion of the string,
> leaving the "?controllerName=channel&id=2"
> rewrite ^/preview.php(.*) / permanent;

rewrite appends args unless the last character of the replacement is "?".

> Essentially I just watch to match against "preview.php" and redirect to
> the index portion of the site.

This description is not the same at the earlier ones.

Assuming that this sentence describes your wish:

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

(untested!) should probably Just Work.

If you *do* want to vary based on the query string (?-bit), the manual
has an example.

Good luck,

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list