Problem with $_SERVER['REQUEST_URI'];

Maxim Dounin mdounin at mdounin.ru
Mon Jun 6 01:28:55 MSD 2011


Hello!

On Sun, Jun 05, 2011 at 04:22:40PM -0400, etrader wrote:

> In my nginx server, $_SERVER['REQUEST_URI']; does not work, and returns
> nothing. When using getenv("REQUEST_URI"); it will returns the url of
> the current page instead of the reffering url. And in this case, it will
> return the current filename (e.g. /test.php) not the full url. I have

REQUEST_URI is expected to contain URI used to access the page in 
question.  I.e. it's expected to contain '/test.php' if you access 
'/test.php' URI.  Note that HTTP historically uses only absolute 
path on an origin server as URI, not the absolute URL.

Reffering url may (or may not) be present in Referer header, which 
should be available in php as HTTP_REFERER.

> tested this on apache, and there is no problem; thus it is something
> related to nginx setting. Any idea?

nginx doesn't execute php scripts by itself, it only passes 
requests to backend you configured (via one of the supported 
protocols, that is http, fastcgi, ...).

As you see getenv("REQUEST_URI") but not $_SERVER['REQUEST_URI'] - 
it looks like data is available on your backend, but for some 
reason only via getenv(), not $_SERVER[].  Check your php backend 
to find out why this happens.

Maxim Dounin



More information about the nginx mailing list