How to Fix URL Fuzzy Matching in WordPress
Alex Young | WordPress Nerd

Intro
Sup, WordPress Nerds! In this guide, learn how to remove fuzzy matching from WordPress URLs. Fuzzy matching is a feature in which WordPress attempts to intelligently predict what was meant when entering a URL. While this can be useful in some situations, it may also create difficulties when trying to track 404 errors on a website. Let’s dive in!
Video version:
Example of Fuzzy Matching
To better understand this issue, let’s look at an example. There are two URLs on a site: “Headless WordPress is great” and “Headless Horseman Origin Story.” If the first one were to be deleted and then an attempt to visit it is made, WordPress would redirect to the second URL because it assumes that’s the intended destination. This behavior can make it challenging to identify and manage genuine 404 errors on a site, which is really important when trying to optimize SEO initiatives.

Solution: Adding a Filter to the Redirect_Canonical Hook
Thankfully, there’s a solution! By adding a filter to the “redirect_canonical” hook in WordPress’s functions.php
file, you can control how those redirects are handled. This filter will check to see if the current page is a 404. If it is, the redirect will be stopped. If it’s not, the redirect will proceed as usual!
add_filter( 'redirect_canonical', function ( $url ) {
if ( is_404() ) {
return false;
}
return $url;
});
Observing the Results
After applying this change, if you visit a deleted URL, you’ll encounter a 404 error rather than being redirected to a similar URL. This makes tracking 404 errors on your website much simpler and gives you a clearer picture of how visitors interact with your site.

Conclusion
While this solution might not be necessary or applicable to every website, it can be incredibly helpful in specific cases. By understanding and addressing the issue of fuzzy matching, the overall management of a website can be improved, and the user experience for visitors can be optimized.
Related Posts:
WordPress Freelancing Tips, Tricks, and Pitfalls
This guide covers communication, choosing tools, plugin policies, admin area tidying, agency networking, and common pitfalls to avoid.
Supercharge Yoast with Custom Tags!
Join me on a user-friendly journey through custom Yoast tags. Boost your WordPress site's SEO with our step-by-step guide - no previous experience required!
Headless WordPress Setup: A Comprehensive Guide
Explore the setup process for a headless WordPress site using Next.js, Tailwind CSS, and popular hosting platforms. Get insights and tips based on real-world experience to help you make informed decisions for your project.