Title: Custom Rewrite Rules &#8211; query_vars issue
Last modified: August 21, 2016

---

# Custom Rewrite Rules – query_vars issue

 *  [Nikos Merianos](https://wordpress.org/support/users/merianos/)
 * (@merianos)
 * [13 years ago](https://wordpress.org/support/topic/custom-rewrite-rules-query_vars-issue/)
 * I have create the following function that is hooked on init action, in order 
   to add my custom re-write rules:
 *     ```
       public function customRewriteRules()
       {
           add_rewrite_tag('%specialty%',  '([^/]+)',  'specialty=');
           add_rewrite_tag('%region%',     '([^/]+)',  'region=');
           add_rewrite_tag('%lngg%',       '([^/]+)',  'lngg=');
           add_rewrite_tag('%zpcd%',       '([^/]+)',  'zpcd=');
           add_rewrite_tag('%find%',       '([1])',    'find=');
   
           add_rewrite_rule(
               '^find/([^/]+)/([^/]+)/([^/]+)/?$',
               'index.php?find=1&specialty=$matches[1]&region=$matches[2]&s=$matches[3]',
               'top'
           );
   
           add_rewrite_rule(
               '^find/([^/]+)/([^/]+)/([^/]+)/page/([0-9]+)/?$',
               'index.php? find=1&specialty=$matches[1]&region=$matches[2]&s=$matches[3]&page=$matches[4]',
               'top'
           );
   
           add_rewrite_rule(
               '^find/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$',
               'index.php?find=1&specialty=$matches[1]&region=$matches[2]&s=$matches[3]&lngg=$matches[4]&zpcd=$matches[5]',
               'top'
           );
   
           add_rewrite_rule(
               '^find/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/page/([0-9]+)/?$',
               'index.php?find=1&specialty=$matches[1]&region=$matches[2]&s=$matches[3]&lngg=$matches[4]&zpcd=$matches[5]&page=$matches[6]',
               'top'
           );
   
           if(get_option('x_rewrite_added', 0) == 0)
           {
               update_option('x_rewrite_added', 1);
               flush_rewrite_rules();
           }
       }
       ```
   
 * When I try the URL
 * [http://www.mysite.com/find/someterm/someterm/somesearch/](http://www.mysite.com/find/someterm/someterm/somesearch/)
 * I get the following query_vars
 *     ```
       [query_vars] => Array
       (
           [s] => none
           [region] => someterm
           [specialty] => someterm
       )
       ```
   
 * and the following query_string
 * **s=none&region=someterm&specialty=someterm**
 * When I try the URL
 * [http://www.mysite.com/find/someterm/someterm/somesearch/page/4](http://www.mysite.com/find/someterm/someterm/somesearch/page/4)
 * I get the following query_vars
 *     ```
       [query_vars] => Array
       (
           [s] => none
           [page] => 4
           [region] => someterm
           [specialty] => someterm
       )
       ```
   
 * and the following query_string
 * **s=none&page=4&region=someterm&specialty=someterm**
 * **But** when I try to enter the following URL:
 * [http://www.mysite.com/find/someterm/someterm/somesearch/someterm/someterm/](http://www.mysite.com/find/someterm/someterm/somesearch/someterm/someterm/)
 * I am getting the following query_vars
 *     ```
       [query_vars] => Array
       (
           [s] => none
           [region] => someterm
           [specialty] => someterm
       )
       ```
   
 * and the following query_string
 * **s=none&region=someterm&specialty=someterm**
 * as weill when I try the
 * **[http://www.mysite.com/find/someterm/someterm/somesearch/someterm/someterm/page/2](http://www.mysite.com/find/someterm/someterm/somesearch/someterm/someterm/page/2)**
 * I am getting the following query_vars
 *     ```
       [query_vars] => Array
       (
           [s] => none
           [page] => 2
           [region] => someterm
           [specialty] => someterm
       )
       ```
   
 * and the following query_string
 * **s=none&page=2&region=someterm&specialty=someterm**

The topic ‘Custom Rewrite Rules – query_vars issue’ is closed to new replies.

## Tags

 * [add_rewrite_tag](https://wordpress.org/support/topic-tag/add_rewrite_tag/)
 * [WP_Rewrite](https://wordpress.org/support/topic-tag/wp_rewrite/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [Nikos Merianos](https://wordpress.org/support/users/merianos/)
 * Last activity: [13 years ago](https://wordpress.org/support/topic/custom-rewrite-rules-query_vars-issue/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
