How to Stop WordPress URL Guessing
Redirect capability is included into the WordPress core and is meant to detect and fix erroneous URLs. If a visitor enters an invalid URL, WordPress tries to find the proper one and, if successful, redirects them.
Consider that your page is located at “http://www.example.com/sport/fotball”. Usually, WordPress is intelligent enough to find the right page to redirect you to automatically if you put “http://example.com/fotball” into your browser.
If a user types in an invalid URL, WordPress will try to guess the proper URL and show it instead of a “Page Not Found” error. Learn how Stop WordPress URL Guessing.
Placing the following PHP code snippet below in your theme’s funtions.php file will Stop WordPress URL Guessing from automatically redirecting a bad URL to an actual post or page with a similar URL.
Please note, if there are any broken links to your website or its pages that benefit from this feature it will now lead to a standard 404 error page.
/* Disable URL guessing */
add_filter('redirect_canonical', 'pz_no_redirect_404');
function pz_no_redirect_404($redirect_url)
{
if (is_404()) {
return false;
}
return $redirect_url;
}
That’s excellent, you could be saying to yourself. The visitor will still arrive where they are expected to even if I mess up a link. You’d be somewhat correct in thinking that. Because WordPress is so adept at determining where URLs are supposed to resolve, incorrectly written URLs frequently work as intended.