[php] what is the difference between $_SERVER['REQUEST_URI'] and $_GET['q']?

what is the difference between $_SERVER['REQUEST_URI'] and $_GET['q'] (which is used in Drupal)?

This question is related to php drupal

The answer is


The PHP manual explains both quite well:

http://php.net/manual/en/reserved.variables.server.php # REQUEST_URI

http://php.net/manual/en/reserved.variables.get.php # for the $_GET["q"] variable


In the context of Drupal, the difference will depend whether clean URLs are on or not.

With them off, $_SERVER['REQUEST_URI'] will have the full path of the page as called w/ /index.php, while $_GET["q"] will just have what is assigned to q.

With them on, they will be nearly identical w/o other arguments, but $_GET["q"] will be missing the leading /. Take a look towards the end of the default .htaccess to see what is going on. They will also differ if additional arguments are passed into the page, eg when a pager is active.