url rewriting – Help with Rewrite Rule for Custom Post Type with Query String


I’m trying to get a custom rewrite working:

I’ve got the following URL pattern for a custom post type of ‘product’:

/au/product/product-name-one/?type=customtype1
/au/product/product-name-one/?type=customtype2

i’m trying to rewrite to:

/au/product/product-name-one/customtype
/au/product/product-name-one/customtype2

==

Here’s what I’ve tried so far:

add_filter( 'query_vars', 'wp_query_vars' );
function wp_query_vars( $query_vars ){
    $query_vars() = 'type';
    return $query_vars;
}

add_action( 'init', 'init_custom_rewrite' );
function init_custom_rewrite() {
    add_rewrite_rule(
        '^au/product/((^/)*)/((^/)*)/?', 
        'index.php?post_type=product&name=$matches(1)&type=$matches(2)','top');
}

Any help would be great