redirect – How do i make WordPress return 404 instead of redirecting on misspelled page?
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?
Leave an answer