How to remove extension with mor rewrite

How to auto add .php after filename with this kind of url:
download?a=x&b=y&…
and auto add index.php if we type www.domain.com/ or domain.com/
I tried but it does not work

if (-f $request_filename/index.php) {
rewrite (.) $1/index.php break;
}
if (-f $request_filename.php) {
rewrite (.
) $1.php break;
}

On Sat, Nov 03, 2007 at 01:40:18AM +0700, Ninh Nguyen wrote:

How to auto add .php after filename with this kind of url: download?a=x&b=y&…
and auto add index.php if we type www.domain.com/ or domain.com/
I tried but it does not work

if (-f $request_filename/index.php) {
rewrite (.) $1/index.php break;
}
if (-f $request_filename.php) {
rewrite (.
) $1.php break;
}

Try the following:

server {

   location = / {
       rewrite  ^   /index.php  last;
   }

   location / {
       if ($request_filename.php) {
           rewrite (.*) $1.php   last;
       }

       root  ...;
       ...
   }

   location ~ \.php$ {
       proxy_pass   or  fastcgi_pass  ...
       ...
   }

It works like charm! Thank you! Great!