What Is A Canonical Redirect?

Canonical redirect may seem to be a rocket science to the average WordPress user, yet they can have a big influence on SEO. The name does not explain anything, but as you will see in this essay, there is nothing complicated here.

First, let us explain the relationship between duplicate and canonical URLs. In simple terms, canonical URLs help search engines find the right address to access the content. This makes it easier for search engine crawlers to understand your website's structure and dismiss URL variants with the same content.

Generally, Google considers multiple URLs that lead to the same page as duplicates. This is where the problem may appear. Because there can only be one canonical URL, only that one is indexed. Duplicated content might be a real nightmare not only for your visitors, but also search engines.

Actually, solving the problem is really simple. In essence, canonicalization is all you need to take control and tell search engines which sites you want them to crawl. You can use either a meta tag with a canonical URL or a "301 redirect" or a mix of the two.

Why Is Canonicalization Important For SEO?

What Are Canonical URLs?

In order to better organize the information in this article, so you can fully understand the canonical redirect, let us first define the canonical URL. In a nutshell, the canonical URL shows Google the correct URL for a certain page when it indexes a website. Although it has no influence on "human" visitors, a canonical URL serves one purpose and is an absolute necessity for SEO.

Considering the problem of duplicated content, there is a possibility that you have a post or page that appears under multiple URL variants. When search engines crawlers determine the "canonical" URL, only that URL will be utilized for displaying search results.

Essentially, Google consider this canonical URL as the most accurate one. If you use WordPress, things are a little easier. Whether you use an SEO plugin or not, WordPress inserts a meta tag with the canonical URL into the HTML code of your page.

How to find canonical URL?
To identify a canonical URL in the HTML source of a webpage, just look for a line of code that has the rel="canonical" tag.
When allowing access to the same content from multiple URLs, be aware that Google's crawling behavior may have an effect on SEO. Google may choose to index a different URL instead of the one specified in the canonical meta tag.

Check out Google Search Central's article on duplicate and canonical URLs for additional details and tips.

What Is A Canonical Redirect?

What is the basic idea behind the canonical redirect? In a nutshell, WordPress uses it to force one version of the URL address (canonical URL) on visitors who try to access different URL versions. In brief, if a page has two or more URLs available for whatever reason, visitors will always be redirected to the canonical URL if they try to access a different version of the URL.

Simply said, alternative URLs may be accessed because WordPress identifies them dynamically using so-called "rewrite rules" based on regular expressions (REGEX). The term or post will be loaded as long as the URL follows the general URL pattern and the last component (slug) matches an existing content item.

So, how does WordPress make advantage of canonical redirects? In order to do this, WordPress uses the "redirect_canonical()" function, which is intended to prevent duplicate content penalty by redirecting all incoming links to the canonical one.

URL in the old (raw) format:
https://example.com/?p=123

Canonical URL (redirect target):
https://example.com/canonical-permalink-of-page-with-id-123/

Guess 404 Permalink Redirect

What is more, the canonical redirect functionality contains one additional, lesser-known component: the "redirect_guess_404_permalink()" function. When you enter a URL that does not exist based on the precise WordPress query (due to a typo or a broken link), it will redirect the user to a similar link. In other words, it tries to "correct" the requested URL and send a visitor to the actual URL address.

Both SEO and UX can benefit from this "guess-redirect" function, although in some cases, it can result in unexpected behavior. Turn it off if you have found that any of your URLs are leading visitors to the incorrect pages and articles. The code snippet that you may use to do so is provided in the final section of this article.

URL with the typo:
https://example.com/product/shirits/cotton/pique-polo

Canonical URL (redirect target):
https://example.com/product/shirts/cotton/pique-polo

What Is An "Old Slug Redirect"?

WordPress also includes a lesser-known "Old slug redirect" functionality that works in a slightly different way than canonical redirect. To put it simply, it provides a fallback for old URLs following a native slug change, preventing the potentially catastrophic "404 not found" error.

It is important to distinguish between the "old slug redirect" and "old custom permalink redirect" functions. The first function is explained below and is included into WordPress core, while the second is a part of Permalink Manager Pro plugin.

Despite the similarity of their names, their functions are unique. The "old custom permalink redirect" is a more complex tool that allows you to save all modifications to custom permalinks as redirects and gives you more control over them.

To begin, WordPress keeps the previous version of the slug as a custom field (_wp_old_slug) in the database whenever you modify it. Then, when someone tries to open any URL in the front-end, the function will check the requested URL address to determine if the extracted slug was previously used as a slug to any page. If this is the case, WordPress will initiate a redirect to the canonical permalink.

Let us assume we created a page called "Cape Verde" and WordPress generated the slug "cape-verde" from it.

Old URL:
https://example.com/africa/cape-verde/

Then we modified the title and native slug to "Cabo Verde" and "cabo-verde" respectively. The original slug "cape-verde" was kept in the database, and now anyone accessing the old URL (see above) will be forwarded to the new one (see below).

Redirect target URL:
https://example.com/africa/cabo-verde/

This particular functionality is rarely used. As mentioned above WordPress saves the old slugs in wp_postmeta table using '_wp_old_slug' meta key. The other problem here is that there is no easy way to list all the saved slugs that will trigger the redirect.

Plugin Settings

As you may know, the URL changes may lead to 404 ("not found") error. In order to avoid this, the plugin has fallback mechanism for the old permalinks. In short, any non-canonical URL variants will be automatically routed to the canonical URL specified by the plugin.

This functionality could be helpful, after you use Permalink Manager to adjust permalinks. In practice, the plugin will automatically redirect all of the original URLs to the new custom permalinks.

If you wish to use this functionality for the original URLs, remember to keep the native settings unchanged ("Settings -> Permalinks"). To make the redirect work, the WordPress core must still recognize the old URLs so that Permalink Manager can recognize which subpage they belong to.

Old (native) URL:
https://example.com/shop/old-original-product-permalink/

New URL (custom permalink, redirect target):
https://example.com/new-url-set-with-permalink-manager/

Automatic redirect
The native permalink (team/john-doe) was used before Permalink Manager was installed. It will lead to new custom permalink (staff/john-doe) set in Permalink Manager.

How To Disable Redirect Functions?

You can deactivate both "Canonical redirect" and "Old slug redirect" in Permalink Manager settings. These functionality is available also in free version of plugin (Permalink Manager Lite).

Canonical redirect settings

If you do not want to install a separate plugin, you may use the following snippet to disable redirect functions:

# Disable canonical redirect completely
remove_action( 'template_redirect', 'redirect_canonical' );
# Disable "old slug" redirection
remove_action( 'template_redirect', 'wp_old_slug_redirect' );
# Disable "guess 404 permalink" redirection
add_filter( 'do_redirect_guess_404_permalink', '__return_false' );
How to use PHP snippets?

If you are not sure where to put the above code, read up on how to add PHP snippet to WordPress.

Frequently Asked Questions

Why Does The Old Url Appear In Google's Search Results?

Even after you have activated the canonical redirect, the old URL can still appear in the search results. Because of the way Google's crawler works, this is not necessarily reason for concern.

Google will not instantly erase the old URL from its search results even if a canonical redirect works. It is all on purpose, since websites sometimes have technical issues and downtime. Googlebot will not remove a URL from the index immediately, allowing website owners time to resolve the issue.

You should know that search engines crawl bigger websites more frequently compared to smaller websites that generate less organic traffic. Therefore, if you have a low-traffic website, an outdated URL may continue to display in search results for months.

The old URL will ultimately vanish as long as you have specified the canonical URL and activated the canonical redirect. The official Google Search Central documentation has further information about this.

What Is A 301 Redirect?

Whenever you try to access any website address (URL), your browser sends a request to that URL's server. However, sometimes the server might tell your browser that this page has permanently changed to a new URL.

In the world of HTTP redirects, a "301" code simply indicates "moved permanently". Simply put, an HTTP redirect instructs your browser to go to a different URL rather than the one you intended to visit.

So, what is the benefit of 301 redirect for SEO? Well, if you move the content without a redirect, search engines will index both the old and new URLs. This results in duplicated content, which is bad for SEO and may harm the search results ranking.

A 301 redirect might also be useful when you remove a page completely. Instead of an annoying 404 "Page Not Found" warning, you can redirect visitors to a similar content.

Go up