function request_path

Returns the requested URL path of the page being viewed.

Examples:

Return value

The requested Drupal URL path.

See also

current_path()

2 calls to request_path()
drupal_environment_initialize in drupal/core/includes/bootstrap.inc
Initializes the PHP environment.
url_alter_test_foo in drupal/core/modules/system/tests/modules/url_alter_test/url_alter_test.module
Menu callback.

File

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

Code

function request_path() {
  static $path;
  if (isset($path)) {
    return $path;
  }

  // Get the part of the URI between the base path of the Drupal installation
  // and the query string, and unescape it.
  $request_path = request_uri(TRUE);
  $base_path_len = strlen(rtrim(dirname($_SERVER['SCRIPT_NAME']), '\\/'));
  $path = substr(urldecode($request_path), $base_path_len + 1);

  // Depending on server configuration, the URI might or might not include the
  // script name. For example, the front page might be accessed as
  // http://example.com or as http://example.com/index.php, and the "user"
  // page might be accessed as http://example.com/user or as
  // http://example.com/index.php/user. Strip the script name from $path.
  $script = basename($_SERVER['SCRIPT_NAME']);
  if ($path == $script) {
    $path = '';
  }
  elseif (strpos($path, $script . '/') === 0) {
    $path = substr($path, strlen($script) + 1);
  }

  // Extra slashes can appear in URLs or under some conditions, added by Apache,
  // so normalize.
  $path = trim($path, '/');
  return $path;
}