Redirect ALL requests to single PHP file

António P. P. Almeida appa at
Wed Jan 18 16:45:14 UTC 2012

On 18 Jan 2012 16h35 WET, nginx-forum at 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?


location = /api.php {
    internal; # comment this out to allow direct access to api.php.
    include fcgi;

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

--- appa

More information about the nginx mailing list