Update: I’ve put together a plugin for this. It’s only a few lines of code, but if you don’t want to add it to your site manually, you can now use the Stop 404 Guessing plugin.
WordPress has a feature called Canonical Redirects which attempts to make sure that users always end up on the one true URL for a given request. That’s great for SEO. Built in to this feature, however, is something that mystifies a lot of developers: when a user reaches a 404, WordPress will use some fuzzy matching try to guess what they meant and redirect them.
To me, this is pretty much the polar opposite of a canonical redirect. I’d much rather have 404s result in a helpful 404 page which I can track in analytics. It can also be very confusing when you’re trying to add your own rewrite rules to WordPress.
Fortunately, you can filter the Canonical Redirect to prevent this strange 404 behavior. Add this to functions.php in your theme:
function stop_404_guessing( $url ) { return ( is_404() ) ? false : $url; } add_filter( 'redirect_canonical', 'stop_404_guessing' );
Now WordPress will continue redirecting to the canonical URL, unless you hit a 404 in which case it will display your 404 page as expected.