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?

  • Your start page, what's its slug? – Tom J Nowell Apr 1 at 12:16
  • @TomJNowell The start page slug is hello. – fbmd Apr 3 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.