4.6.x bootstrap.inc request_uri()
4.7.x bootstrap.inc request_uri()
5.x bootstrap.inc request_uri()
6.x bootstrap.inc request_uri()
7.x bootstrap.inc request_uri()

Returns the equivalent of Apache's $_SERVER['REQUEST_URI'] variable.

Because $_SERVER['REQUEST_URI'] is only available on Apache, we generate an equivalent using other environment variables.

11 calls to request_uri()
DBLogTestCase::generateLogEntries in modules/dblog/dblog.test
Generates a number of random database log events.
DBLogTestCase::testDBLogAddAndClear in modules/dblog/dblog.test
Tests the addition and clearing of log events through the admin interface.
DBLogTestCase::testDBLogException in modules/dblog/dblog.test
Verifies that exceptions are caught in dblog_watchdog().
drupal_fast_404 in includes/bootstrap.inc
Returns a simple 404 Not Found page.
drupal_page_get_cache in includes/bootstrap.inc
Retrieves the current page from the cache.

... See full list


includes/bootstrap.inc, line 1886
Functions that need to be loaded on every Drupal request.


function request_uri() {
  if (isset($_SERVER['REQUEST_URI'])) {
    $uri = $_SERVER['REQUEST_URI'];
  else {
    if (isset($_SERVER['argv'])) {
      $uri = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['argv'][0];
    elseif (isset($_SERVER['QUERY_STRING'])) {
      $uri = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING'];
    else {
      $uri = $_SERVER['SCRIPT_NAME'];

  // Prevent multiple slashes to avoid cross site requests via the Form API.
  $uri = '/' . ltrim($uri, '/');
  return $uri;


matt2000’s picture

$GLOBALS['base_url'] => http://example.com/drupal
base_path() => /drupal/
request_uri() => /drupal/documentation?page=1
request_path() => documentation
current_path() => node/26419

kris-o3’s picture

very helpful short/sweet run-down of the differences among these functions!

cdmo’s picture

Agreed, very helpful information, always find myself trying to remember these. arg() isn't mentioned here, because its use is discouraged I imagine.

miltonsp’s picture

I believe

$GLOBALS['base_url'] => http://example.com/drupal

Should be:

$GLOBALS['base_url'] => http://example.com

drubb’s picture

The base_url global contains the base_path of the drupal installation, and this might be a subdirectory like 'drupal'. If you don't need this, there's another global variable named 'base_root', which doesn't contain the base path:

$GLOBALS['base_url'] => http://example.com/drupal
$GLOBALS['base_root'] => http://example.com

By the way, perhaps one should use the global variables supplied by Drupal, so instead of using

$root = $GLOBALS['base_root']

we should better use

global $base_root;
$root = $base_root;


This might save some headaches one day.