I'm trying to get a rewrite_rules_array rule to work and running into issues. I would like to add a rule so that when someone visits:


It essentially loads:


What really happens is that Wordpress redirects you to http://domain.com/product/foo.

add_filter('rewrite_rules_array', function( $rules ) {
    $new = array();
    $new['product/(.*)/(.*)/?'] = 'index.php?pagename=$matches[1]&view=$matches[2]';
    return array_merge( $new, $rules );
  • I've flushed my permalinks.
  • view has been added to the query_vars.
  • Your products are pages of the page post type? Also- just use add_rewrite_rule hooked to init if you’re just adding rules and not manipulating existing rules or reordering.
    – Milo
    Nov 14, 2018 at 23:00
  • @Milo They are of type 'product'.
    – Louis W
    Nov 15, 2018 at 2:19

1 Answer 1


For anyone looking, the solution was:

add_action('init', function() {



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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