I'm creating some custom rewrites using the code below. Everything works fine, as far as urls such as this:


Tells my theme to use the special archive page and passes the parameters I need. The problem I run into is with pagination. Wordpress generates the links properly:


but the result is a page not found. My first thought was to add a second rewrite:

 'reviews/(.+)/(.+)/(.+)' =>  'index.php?reviews=1&showarchive=1&category_name=' . $wp_rewrite->preg_index(1) . '&pgd=' . $wp_rewrite->preg_index(2) . '&pgn=' . $wp_rewrite->preg_index(3),

So that I could capture the 'page' and the page number and use those to code an offset into the query and set the paged query var, but I find when I add this it cancels out the other so that:


Now returns page not found but


Works. For SEO purposes I'd like to keep the


Style url without /page/1 — is there any way to get the rewrites working for both conditions?

add_filter('query_vars', 'eparchive_queryvars' );

function eparchive_queryvars( $qvars )
  $qvars[] = 'showarchive';
  $qvars[] = 'reviews';
  $qvars[] = 'pgd';
  $qvars[] = 'pgn';
  return $qvars;

add_action('generate_rewrite_rules', 'custom_add_rewrite_rules');

    function custom_add_rewrite_rules( $wp_rewrite ) 
      $new_rules = array( 

         'reviews/(.+)' =>  'index.php?reviews=1&showarchive=1&category_name=' . $wp_rewrite->preg_index(1)
      $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;

1 Answer 1


You can try these rules:


It's informative to check out the active rewrite rules with:

function show_rewrite_rules( $rules ) {
    if(is_admin()) echo "<pre>".print_r($rules,true)."</pre>";
    return $rules;

and then visit /wp-admin/options-permalink.php.

There exists also some good plugins for analysing the rewrite rules, for example the Monkeyman Rewrite Analyzer.

  • Thanks Birgire! I guess it was a matter of using the right example.
    – MikeGWP
    Commented Apr 10, 2013 at 15:51

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.