I have actor and genre taxonomies.

add_filter('query_vars', 'ap_register_query_vars');
function ap_url_redirect_rules(){
    add_rewrite_rule('([^/]+)?$', 'index.php?actor=$matches[1]', 'top'); // .com/brad-pitt
    add_rewrite_rule('([^/]+)/([^/]+)?$', 'index.php?actor=$matches[1]&sort=$matches[2]', 'top'); // .com/brad-pitt/popular or new, etc.
    add_rewrite_rule('genre/([^&]+)?$', 'index.php?genre=$matches[1]', 'top'); // .com/genre/comedy
    add_rewrite_rule('genre/([^/]+)/([^/]+)?$', 'index.php?genre=$matches[1]&sort=$matches[2]', 'top'); // .com/genre/popular or new, etc.
function ap_register_query_vars($query_vars){
    return $query_vars;

I have this code. Actor rewrite rule is working but genre and single post (post link) not working (404 Page Not Found). What is my wrong?

1 Answer 1


I would think that .com/genre/comedy is actually picked up by the second rule since it matches that as well, and because it is added first I think it takes precedence.

You could try to swap the order, so it goes 3, 4, 1, 2.

For production, you might want to remove flush_rewrite_rules();, I believe it's quite expensive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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