$input->canonicalUrl() method

Generate canonical URL for current page and request

Canonical URL includes full scheme, hostname, path and optionally: URL segments, page numbers and query string.

Available since version 3.0.155.

Usage

// basic usage
$string = $input->canonicalUrl();

// usage with all arguments
$string = $input->canonicalUrl(array $options = []);

Arguments

NameType(s)Description
options (optional)array
  • scheme (string|bool): Scheme "https", "http", or omit to auto-detect (default='').
  • host (string): Hostname or omit to use current http host (default='').
  • page (Page): Page to use for URL or omit for current Page (default=$page).
  • urlSegments (array|string|bool): True to include current URL segments, false to disable, or specify array or string of URL segments to use (default=true).
  • notSegments (array|string): Full URL segments or patterns (wildcard or regex) to exclude from canonical URL (default=[])
  • pageNum (bool|int): True to include current page/pagination number, false to disable, or specify pagination number (int) to use (default=true).
  • queryString (bool|string|array): True to use current whitelist query string, false to disable, or specify array of query string vars, or actual query string as string (default=true).
  • language (bool|Language): True for current language, false to force default or no language, or specify Language object to use that language. (default=true)

Return value

string


$input methods and properties

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #523
    In the 523rd issue of ProcessWire Weekly we'll check out what's new in the core this week, share some new module related news, and more. Read on!
    Weekly.pw / 18 May 2024
  • ProFields Table Field with Actions support
    This week we have some updates for the ProFields table field (FieldtypeTable). These updates are primarily focused on adding new tools for the editor to facilitate input and management of content in a table field.
    Blog / 12 April 2024
  • Subscribe to weekly ProcessWire news

“To Drupal, or to ProcessWire? The million dollar choice. We decided to make an early switch to PW. And in retrospect, ProcessWire was probably the best decision we made. Thanks are due to ProcessWire and the amazing system and set of modules that are in place.” —Unni Krishnan, Founder of PigtailPundits