Skip to main content
replaced http://wordpress.stackexchange.com/ with https://wordpress.stackexchange.com/
Source Link

So the problem was redirect_guess_404_permalink was detecting a 404 error and 'guessed' /members/blog to be /blog

My hacky solution was to hook into the status error check (Stop Wordpress from "guessing" redirects for nonexistent URLsStop Wordpress from "guessing" redirects for nonexistent URLs) and if URL parts match then unset the guessed solution

function blog_no_redirect_guess_404_permalink( $header ){
    global $wp_query;

    if( is_404() ) {
        // Get Request URL Parts
        $url = parse_url($_SERVER['REQUEST_URI']);
        $path = explode('/', $url['path']);
        $path = array_filter($path);
        $path = array_merge($path, array());
        // If matches /members/blog then unset 'guess'
        if (strtolower($path[0]) == 'members' && strtolower($path[1]) == 'blog') {
            unset( $wp_query->query_vars['name'] );
        }
    }
       
    return $header;
}
add_filter( 'status_header', 'blog_no_redirect_guess_404_permalink' );

So the problem was redirect_guess_404_permalink was detecting a 404 error and 'guessed' /members/blog to be /blog

My hacky solution was to hook into the status error check (Stop Wordpress from "guessing" redirects for nonexistent URLs) and if URL parts match then unset the guessed solution

function blog_no_redirect_guess_404_permalink( $header ){
    global $wp_query;

    if( is_404() ) {
        // Get Request URL Parts
        $url = parse_url($_SERVER['REQUEST_URI']);
        $path = explode('/', $url['path']);
        $path = array_filter($path);
        $path = array_merge($path, array());
        // If matches /members/blog then unset 'guess'
        if (strtolower($path[0]) == 'members' && strtolower($path[1]) == 'blog') {
            unset( $wp_query->query_vars['name'] );
        }
    }
       
    return $header;
}
add_filter( 'status_header', 'blog_no_redirect_guess_404_permalink' );

So the problem was redirect_guess_404_permalink was detecting a 404 error and 'guessed' /members/blog to be /blog

My hacky solution was to hook into the status error check (Stop Wordpress from "guessing" redirects for nonexistent URLs) and if URL parts match then unset the guessed solution

function blog_no_redirect_guess_404_permalink( $header ){
    global $wp_query;

    if( is_404() ) {
        // Get Request URL Parts
        $url = parse_url($_SERVER['REQUEST_URI']);
        $path = explode('/', $url['path']);
        $path = array_filter($path);
        $path = array_merge($path, array());
        // If matches /members/blog then unset 'guess'
        if (strtolower($path[0]) == 'members' && strtolower($path[1]) == 'blog') {
            unset( $wp_query->query_vars['name'] );
        }
    }
       
    return $header;
}
add_filter( 'status_header', 'blog_no_redirect_guess_404_permalink' );
Source Link
ptimson
  • 243
  • 1
  • 4
  • 12

So the problem was redirect_guess_404_permalink was detecting a 404 error and 'guessed' /members/blog to be /blog

My hacky solution was to hook into the status error check (Stop Wordpress from "guessing" redirects for nonexistent URLs) and if URL parts match then unset the guessed solution

function blog_no_redirect_guess_404_permalink( $header ){
    global $wp_query;

    if( is_404() ) {
        // Get Request URL Parts
        $url = parse_url($_SERVER['REQUEST_URI']);
        $path = explode('/', $url['path']);
        $path = array_filter($path);
        $path = array_merge($path, array());
        // If matches /members/blog then unset 'guess'
        if (strtolower($path[0]) == 'members' && strtolower($path[1]) == 'blog') {
            unset( $wp_query->query_vars['name'] );
        }
    }
       
    return $header;
}
add_filter( 'status_header', 'blog_no_redirect_guess_404_permalink' );