General rule for rewrite

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

I have similar rewrites too; I wonder if it is possible to write a
general rule to do so for all php files?
I mean rewrites filename.php?q=something to /filename/something.html

instead of writing a rewrite rule for each php file

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,212912,212912#msg-212912

On 25 Jul 2011 13h35 WEST, [email protected] wrote:

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

Try this:

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

Or the more “standard” approach:

location ~ /(?[^/])/(?.).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.

  • location ~ /(?[^/])/(?.).html$
  • location ~ ^/(?[^/])/(?.).html$

— appa

Oops. Again :frowning:

  • location ~ ^/(?[^/])/(?.).html$
  • location ~ ^/(?[^/])/(?.).html$

— appa