Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Request.php

function Request::prepareRequestUri

1 call to Request::prepareRequestUri()
Request::getRequestUri in vendor/symfony/http-foundation/Request.php
Returns the requested URI (path and query string).

File

vendor/symfony/http-foundation/Request.php, line 1742

Class

Request
Request represents an HTTP request.

Namespace

Symfony\Component\HttpFoundation

Code

protected function prepareRequestUri() : string {
    $requestUri = '';
    if ($this->isIisRewrite() && '' != $this->server
        ->get('UNENCODED_URL')) {
        // IIS7 with URL Rewrite: make sure we get the unencoded URL (double slash problem)
        $requestUri = $this->server
            ->get('UNENCODED_URL');
        $this->server
            ->remove('UNENCODED_URL');
    }
    elseif ($this->server
        ->has('REQUEST_URI')) {
        $requestUri = $this->server
            ->get('REQUEST_URI');
        if ('' !== $requestUri && '/' === $requestUri[0]) {
            // To only use path and query remove the fragment.
            if (false !== ($pos = strpos($requestUri, '#'))) {
                $requestUri = substr($requestUri, 0, $pos);
            }
        }
        else {
            // HTTP proxy reqs setup request URI with scheme and host [and port] + the URL path,
            // only use URL path.
            $uriComponents = parse_url($requestUri);
            if (isset($uriComponents['path'])) {
                $requestUri = $uriComponents['path'];
            }
            if (isset($uriComponents['query'])) {
                $requestUri .= '?' . $uriComponents['query'];
            }
        }
    }
    elseif ($this->server
        ->has('ORIG_PATH_INFO')) {
        // IIS 5.0, PHP as CGI
        $requestUri = $this->server
            ->get('ORIG_PATH_INFO');
        if ('' != $this->server
            ->get('QUERY_STRING')) {
            $requestUri .= '?' . $this->server
                ->get('QUERY_STRING');
        }
        $this->server
            ->remove('ORIG_PATH_INFO');
    }
    // normalize the request URI to ease creating sub-requests from this request
    $this->server
        ->set('REQUEST_URI', $requestUri);
    return $requestUri;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal