WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;
share|improve this question
up vote 0 down vote accepted

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.

share|improve this answer
Thanks Birgire! I guess it was a matter of using the right example. – MikeGWP Apr 10 '13 at 15:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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