Stop URL Autocorrect Guessing

WORDPRESS CODE SNIPPET

Maybe you’ve never noticed the URL Autocorrect Guessing feature of WordPress yet. WordPress tries to guess a redirection for a nonexistent URL if the slug is at the beginning of another URL.

By way of example if someone tries to access the URL http://example.com/hello but there is no page or post with that URL, then WordPress tries to guess the URL and e.g. redirects to the URL http://example.com/hello-world if this URL exists, because the URL starts with “hello”.

This may be useful – or not. In my opinion it makes more sense to serve a 404 error. This enables you to monitor this cases and correct broken links.

This tiny piece of code stops WordPress from guessing URLs which results in a 404 error if an URL does not exist.

Share this page: