Understanding Canonical Redirect in WordPress

Although many people have heard of "canonical URLs" and "canonical redirects", they may not realize how crucial they are. They help search engines identify the correct URL and avoid showing duplicate content to visitors.

In simple terms, canonical redirects tell search engines and browsers which URL is the main one when there are multiple URLs leading to the same content. This matters because if search engines see multiple versions of the same page, they may index the wrong URL instead of the correct one.

Canonical redirect graphic

How Canonical Redirects Work in WordPress?

What Are Canonical URLs?

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.

WordPress added this feature in 2007 with version 2.3. Before that, the same page could be accessed through multiple URLs, whether with or without "www", a shortened slug, or added query parameters.

This confused search engines, which could not always determine the correct version to index, sometimes leading to duplicate content issues.

How to find canonical URL?
The simplest way to check which URL a page is meant to use is by looking at its HTML source code.
Having this tag does not guarantee that Google will always follow it. If a page is available under multiple URLs, Google might select a different one to index, which could influence how it appears in search rankings.

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.

To give you a clearer picture, let’s say we created a page called "Cape Verde", and the slug generated was "cape-verde".

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

In case we update the title to "Cabo Verde" and modify the slug to "cabo-verde", the old slug will still exist in the database. WordPress will handle the redirection to the correct page for anyone who tries to visit the old URL.

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

Although this functionality seems like it could be effective, the biggest drawback is that there is no easy way to get a list of all the saved slugs that will trigger the redirect.

Troubleshooting

Canonical redirects prevent duplicate content across multiple URLs and ensure visitors are sent to the right page if a URL changes.

However, they do not always work properly, often due to conflicts with plugins. The problem can become even harder to fix when server-side redirects, set in .htaccess or NGINX configuration files, interfere.

It is important to address this quickly to avoid making your content inaccessible and losing traffic. If ignored, this can frustrate visitors and harm your search engine ranking.

Why Is Canonicalization Important?

If you are wondering how to handle duplicate pages, Google offers solid advice on how to handle them with canonicalization.

The best way to avoid this issue is to act before it becomes a problem. Most SEO plugins handle this automatically, but it is worth double-checking that everything is working properly.

Here is what you should check:

  • 301 redirects are used to ensure everyone lands on the correct page.
  • All internal links point to the right canonical URL.
  • Unwanted URL variations are removed from the XML sitemap.

Analyzing HTTP Headers

A good starting point is checking HTTP headers to determine whether WordPress or a plugin is responsible for the issue. In WordPress, the redirects performed by the native wp_redirect() function send an extra HTTP header: "X-Redirect-By".

Normally, this header is set to "WordPress", but many plugins — such as Yoast SEO and Rank Math—modify it to display their own names instead. This can provide a helpful clue about which plugin triggered the redirect.

HTTP response with "X-Redirect-By" header

Other Methods

Another easy way to debug redirect issues is to deactivate plugins and your theme one at a time. This should help you figure out which one could be causing the issue with the canonical redirect.

You can also try WP Core Monitor, which you can download for free, offers a Redirect Debugger that can help you pinpoint exactly which plugin is triggering the redirect.

WP Core Monitor redirect tool
WP Core Monitor Redirect Debugger tool

If the issue persists and the steps above didn’t work, this article provides additional suggestions and other options to try.

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

How To Disable Canonical Redirect Without Plugin?

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 how or where to place the code snippet above, this article will walk you through the process with easy instructions.

Frequently Asked Questions

Why Does Google Keep Displaying The Old URL In Its 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.

Last updated by Maciej Bis on: March 3, 2025.


Maciej BisFounder of Permalink Manager & WordPress Developer

The developer behind Permalink Manager, a plugin for managing permalinks, has been working with WordPress, creating custom plugins and themes, for more than a decade.

Go up