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.
In general, Google will treat multiple URLs that lead to the same page as duplicates of the same page. Since there can be only one canonical URL, only that one will be indexed. If Google can not figure out what the actual URL of the affected content is, it could impact SEO ranking.
To avoid this, you need to understand the nature of the problem. This article will not only explain it, but also provide a few useful suggestions on how to address it. We will also take a look at WordPress's built-in tools that can help you prevent duplicated permalinks.
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.
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, when Google indexes a website, the canonical URL informs search engine crawlers of the actual URL address of the specific page. 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. Thankfully, WordPress users do not have to worry about it. WordPress will still generate this tag into the page code for you even if you do not use an SEO plugin.
Check out Google Search Central's article on duplicate and canonical URLs for additional details and tips.
What is a canonical redirect?
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 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.
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.
URL with the typo:
Canonical URL (redirect target):
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.
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.
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.
How does canonical redirect affects custom permalinks?
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.
Old (native) URL:
New URL (custom permalink, redirect target):
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).
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' );
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 be aware that bigger websites get crawled more often than 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.
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.