WordPress.org

Ready to get started?Download WordPress

Codex

Function Reference/redirect canonical

Contents

Description

Redirects incoming links to the proper URL based on the site url.

Search engines consider www.somedomain.com and somedomain.com to be two different URLs when they both go to the same location. This SEO enhancement prevents penalty for duplicate content by redirecting all incoming links to one or the other.

Prevents redirection for feeds, trackbacks, searches, comment popup, and admin URLs. Does not redirect on IIS, page/post previews, and on form data.

Will also attempt to find the correct link when a user enters a URL that does not exist based on exact WordPress query. Will instead try to parse the URL or query in an attempt to figure the correct page to go to.

Usage

<?php redirect_canonical$requested_url$do_redirect ); ?>

Parameters

$requested_url
(string) (optional) Optional. The URL that was requested, used to figure if redirect is needed.
Default: null
$do_redirect
(boolean) (optional) Optional. Redirect to the new URL.
Default: true

Return Values

(null|false|string) 
Null, if redirect not needed. False, if redirect not needed or the string of the URL

Change Log

Since: 2.3

Source File

redirect_canonical() is located in wp-includes/canonical.php