Wordpress重写存档规则

So I'm having an issue with rewrite rules in WordPress.

When I input a custom query that isn't there, it reverts back to index.php, but I don't want it to, because I'm handling the query variables in the archive-(page).php.

<?php
    add_filter('query_vars', 'cat_query_vars');
    function cat_query_vars($qvars) {
        $qvars[] = 'a_type';
        return $qvars;
    }

    add_action('init', 'create_type_rewrite');
    function create_type_rewrite() {
        add_rewrite_rule('^atype/([^/]+)/?', 'index.php?post_type=cars&a_type=$matches[1]', 'top');
    }
?>

If I put in "Mercedes" and it's in the system, it will go to archive-cars.php, and use get_posts($args), where I have 'a_type' => $wp_query->query_vars['a_type'];. There is a global $wp_query.

I'm still having an issue though, say if I have a custom taxonomy "Mercedes" in there it will pull up results for all relating to "Mercedes" but if I put in "sadfasdf" it will default to index.php for some reason.

You add query vars like this...

function add_my_query_var($vars) {
    $vars[] = 'my_var';
    return $vars;
}

add_filter('query_vars', 'add_my_query_var');

the filter function is passed an array of the existing query vars, you need to append that array and then return it.