Redirect ALL requests to single PHP file

Hi All,

We’d like to redirect all requests to a single PHP file. The
configuration below is what we have but I’m concerned that it would
cause an “infinite” loop and possibly other problems. We’d like to
redirect ANY request to api.php regardless if the file exists or not.
Even a request to an existing static file should rewrite to the
“api.php” file.

Is this the correct way? is there a better way?

Thanks

    server
    {
            listen #.#.#.#:80;
            server_name api.domain.com;

            rewrite ^(.*)$ /api.php?uri=$1 last;

            location ~ \.php$
            {
                    include fcgi;
                    fastcgi_pass 127.0.0.1:9000;
            }
    }

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

On 18 Jan 2012 16h35 WET, [email protected] wrote:

Hi All,

We’d like to redirect all requests to a single PHP file. The
configuration below is what we have but I’m concerned that it would
cause an “infinite” loop and possibly other problems. We’d like to
redirect ANY request to api.php regardless if the file exists or
not. Even a request to an existing static file should rewrite to
the “api.php” file.

Is this the correct way? is there a better way?

Try:

location = /api.php {
internal; # comment this out to allow direct access to api.php.
include fcgi;
fastcgi_pass 127.0.0.1:9000;
}

location / {
return 302 /api.php?uri=$request_uri;
}

— appa

Hello!

On Wed, Jan 18, 2012 at 11:35:24AM -0500, iberkner wrote:

            {
                    include fcgi;
                    fastcgi_pass 127.0.0.1:9000;
            }
    }

server {
listen …
server_name api.domain.com;

location / {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param REQUEST_FILENAME $document_root/api.php;
    include fastcgi_params;
}

}

Maxim D.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs