general rule for rewrite

António P. P. Almeida appa at perusio.net
Mon Jul 25 12:53:53 UTC 2011


On 25 Jul 2011 13h35 WEST, nginx-forum at nginx.us wrote:

> I use this rewrite rule to create SEO friendly urls
> rewrite ^/search/(.*).html /search.php?q=$1 last;

Try this:

location ~ ^/(?<file1>[^/]*)/(?<file2>.*)\.html$ {
   return 302 /$file1.php?q=$file2;
}

Or the more "standard" approach:

location ~ /(?<file>[^/]*)/(?<file2>.*)\.html$ {
   rewrite ^ /$file1.php?q=$file2 last;
}

--- appa

PS: Don't know which version if Nginx is required to make the first
rule work. It's an undocumented feature. It works with 1.0.5. Try it.



More information about the nginx mailing list