redirect – How do i make WordPress return 404 instead of redirecting on misspelled page?

Question

In a vanilla wordpress install, a misspelled page such as https://example.com/weclome leads to a 404 error, which is fine.

However, once I set custom permalinks for posts such as https://example.com/data/%postname%/ , the very same misspelled link https://example.com/weclome no longer 404s, but sends a 301 redirect to the start page https://example.com/ .

I have deactivated all plugins, the problem persists.

I tried:

remove_action('template_redirect', 'wp_old_slug_redirect');

remove_filter('template_redirect', 'redirect_canonical');

add_filter('redirect_canonical', 'no_redirect_on_404');
function no_redirect_on_404($redirect_url)
{
    if (is_404()) {
        return false;
    }
    return $redirect_url;
}

add_filter( 'do_redirect_guess_404_permalink', '__return_false' );

in functions.php, none of which works.

How can I have custom permalinks as shown, and still have misspelled or unknown pages 404 instead of 301 redirect?

0
fbmd 1 month 2021-04-01T05:06:39-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse