What Is A Canonical Redirect?

Canonical redirect may be confusing to the average WordPress user, yet they can have a big influence on search engine optimization. This article's goal is to provide you with all of the necessary information concerning them.

Simply said, if a single page can be reached through many URLs, Google will treat them as duplicates of the same page and will choose only one URL as the canonical one to be indexed. If this occurs on your website, Google will either pick the URL for you or consider both URLs to be equal, which might result in a substantially lower rank in search results. Even worse, the search engine may pick the incorrect page as the original, displaying outdated content.

The article not only explains the nature of the problem, but it also offers some useful suggestions for dealing with the duplicate URLs issue.

Duplicate content can be a real nightmare for both visitors and search engines. Regardless of how bad it seems, this is a simple problem to solve. In essence, canonicalization is all you need to take control and tell search engines which pages you want them to crawl. You may use a meta tag with a canonical URL or a "301 redirect" or a combination of the two.

Despite its flaws, WordPress can handle this issue quite reliably. Now we will look at one of its built-in features that aims to solve the issue of duplicate permalinks.

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

Why is canonicalization important for SEO?

What are canonical URLs?

Before we get into the specifics of canonical redirect, it is important to first understand what a canonical URL is. In a nutshell, this element tells search engine crawlers the precise URL address of the page that is now being processed. Although it has no effect on "human" visitors, a canonical URL serves one purpose and is an absolute necessity for SEO.Why is this the case? Considering the problem of duplicated content, there is a possibility that you have a post or page that appears under two URLs. When multiple URLs contain identical or extremely similar content, the canonical meta tag tells search engines which page to index. Once Google and other search engines know which one is the "canonical" URL, it will show that URL in search results. In other words, Google defines a canonical URL as the URL of the most representative page among a set of duplicate pages.

How to find canonical URL?
To find a canonical URL in a webpage's HTML source, look for a line of code that contains the rel="canonical" attribute. It is solely visible to search engines and has no effect on your site visitors.

The good news is that those of you who use WordPress are in luck. Few people are aware that WordPress automatically inserts this tag into the page code, even if no SEO plugin is installed. If necessary, there is a dedicated function that you may use to get the canonical URL for a certain post or page.

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.

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? The best way to ensure that both users and search engines are forwarded to the proper page is via a server-side redirection. 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:

Canonical URL (redirect target):

Guess 404 permalink redirect

What is more, the canonical redirect functionality contains one additional, lesser-known component: the "redirect_guess_404_permalink()" function. When a user enters a URL that does not exist based on the precise WordPress query, it attempts to 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.

This "guess-redirect" feature is useful for both SEO and UX, but it might cause some strange behavior in certain circumstances. If you have discovered that any of your URLs are redirecting to odd URLs and articles, you should turn it off. The code snippet that you may use to do so is provided in the final section of this article.

What is an "old slug redirect"?

Apart from addressing the duplicate content issue with canonical redirects, WordPress has another interesting feature that was built specifically to avoid SEO penalties.

It is lesser-known "Old slug redirect," which functions similarly to 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:

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:

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, any (original) URLs that were active prior to the installation of plugin will be automatically redirected to the new 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:

New URL (custom permalink, redirect target):

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 use PHP snippets.

Frequently asked questions

Why does the old URL appear in Google's search results?

It is possible that even after you have activated the canonical redirect, the old URL will appear in Google search results and Search Console. Because of the way Google's crawler works, this is not necessarily a negative thing.

Google will not instantly erase the old URL from its search results even if a canonical redirect redirects the user to the new one. This is done on purpose, since websites sometimes have technical issues and downtime, and Googlebot will not instantly remove a URL from the index if it is detected to be missing.

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

You should be aware that bigger websites get crawled more often than smaller websites that generate less organic search traffic. In the worst-case situation, if you have a small website with few visitors, an outdated URL may continue to display in search results for months.

Go up