Wordpress - Disable ONLY URL auto complete, not the whole canonical URL system

Updated Answer (2020-10-29):

The solution has changed with Wordpress 5.5. Keeping the old answer for reference below.

Short version: Get my pluign from here: https://wordpress.org/plugins/disable-url-autocorrect-guessing/

Long Version:

With Wordpress 5.5, you can control more precisely if/how the guessing should work. Refer to https://make.wordpress.org/core/2020/06/26/wordpress-5-5-better-fine-grained-control-of-redirect_guess_404_permalink/ for more information. To completely disable guessing, use this code:

add_filter( 'do_redirect_guess_404_permalink', '__return_false' );

If you add this to a new plugin php file (for example in wp-content/plugins/disable-url-autocorrect-guessing.php) you'll have a nice plugin that you can activate to disable Wordpress' autocorrect "guessing" feature.

To save you the trouble to do this, I've updated my plugin; version 2.0 uses this oneliner now. You can get the plugin from here: https://wordpress.org/plugins/disable-url-autocorrect-guessing/


Old answer (before 2020-10-29):

Okay, after searching a bit more I finally found an answer to my own question hidden in a comment of this feature request ticket: https://core.trac.wordpress.org/ticket/16557 The user nacin suggested to use this code:

function remove_redirect_guess_404_permalink( $redirect_url ) {
    if ( is_404() )
        return false;
    return $redirect_url;
}

add_filter( 'redirect_canonical', 'remove_redirect_guess_404_permalink' );

If you add this to a new plugin php file (for example in wp-content/plugins/disable-url-autocorrect-guessing.php) you'll have a nice plugin that you can activate to disable Wordpress' autocorrect "guessing" feature.

In order to save you the trouble I actually did this and handed in my plugin at Wordpress.org. Once it gets reviewed there, you should be able to download it here: https://wordpress.org/plugins/disable-url-autocorrect-guessing/


While this is a working solution, the suggested code is somewhat of a hack. Once the feature request in https://core.trac.wordpress.org/ticket/16557 is actually implemented, there will be way better solutions for this as well as much better control over how the guessing should actually be performed.

Tags:

Redirect

Urls