WordPress total posts per page changed and now 404 Http error comes out [closed]

The only way to really know if it’s going to be a 404 is to let WordPress try to load it and check results before WP sends headers.

If you put this in your functions.php (not on a live site! use a dev mirror.), then visit a page that throws a 404, you can see the contents of the $wp_query object produced, is_404 will be true. By inspecting this you can determine what you want to do.

add_filter('template_redirect', 'wpse25745_inspect_query' );
function wpse25745_inspect_query() {
    global $wp_query;

    echo '<pre>';
    print_r($wp_query);
    echo '</pre>';
    die();

}

Following on that, you can redirect somewhere like this:

add_filter('template_redirect', 'wpse25745_inspect_query' );
function wpse25745_inspect_query() {
    global $wp_query;

    if( $wp_query->is_404 && $some_other_conditions_met == 'foo' ):
        wp_redirect( home_url(),301 );
        exit;
    endif;
}