Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Wordpress sometimes "guesses" a redirection for a nonexistent page slug if the slug is at the beginning of another URL. After some searching, my hypothesis is that this part of the canonical redirection functionality, which can be disabled using this code:

remove_filter('template_redirect', 'redirect_canonical'); 

However, I like the idea of canonical redirection, and would prefer not to turn it off entirely. Is there a way to only disable the slug "guessing"? I would prefer a 404 over an incorrect 301.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

It's a bit hacky, but this should work:

function no_redirect_guess_404_permalink( $header ){
    global $wp_query;

    if( is_404() )
        unset( $wp_query->query_vars['name'] );

    return $header;
}

add_filter( 'status_header', 'no_redirect_guess_404_permalink' );
share|improve this answer
    
Thanks, that did the trick! –  supertrue Sep 9 '11 at 0:31
    
Would it be less hacky to hook this into redirect_canonical instead of status_header? As in the winning answer here— wordpress.stackexchange.com/questions/3326/… –  supertrue Sep 9 '11 at 0:35
    
Yeah, that's a much better solution. –  postpostmodern Sep 9 '11 at 16:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.