1.1.5. URL

The Request $url property is an instance of a Url object.

Each Url object has these properties:

  • ?string $scheme
  • ?string $host
  • ?int $port
  • ?string $user
  • ?string $pass
  • ?string $path
  • ?string $query
  • ?string $fragment

The property values are derived from applying parse_url() to the various Request $server elements:

  • If $server['HTTPS'] === 'on', the scheme is 'https'; otherwise, it is 'http'.

  • If $server['HTTP_HOST'] is present, it is used as the host name; otherwise, $server['SERVER_NAME'] is used.

  • If a port number is present on the host name, it is used as the port; otherwise, $server['SERVER_PORT'] is used.

  • $server['REQUEST_URI'] is used for the path and query string.

If the parsing attempt fails, all Url properties will be null.

The Url is stringable, and will return the full URL string:

$url = (string) $request->url; // https://example.com/path/etc