Title: Problem with WP Rewrite
Last modified: August 19, 2016

---

# Problem with WP Rewrite

 *  [kemper-boyd](https://wordpress.org/support/users/kemper-boyd/)
 * (@kemper-boyd)
 * [16 years ago](https://wordpress.org/support/topic/problem-with-wp-rewrite/)
 * I need to rewrite an address like this:
 * `http://example.com/galleria/artist-name`
 * so that it goes to the gallery.php page with a variable containing ‘artist-name’.
   I used the same syntax as in the wp rewrite documentation and while it works 
   fine on my local wordpress install, on the real server it has a strange behavior:
   the original URL is accepted (i.e. it doesn’t end in a 404) but it gets rewritten
   to
 * `http://example.com/gallery`
 * (I mean actually rewritten in the browser’s address bar) and the variable is 
   not set.
 * Rules used:
 *     ```
       // REWRITE RULES (per gallery) {{{
       add_filter('rewrite_rules_array','wp_insertMyRewriteRules');
       add_filter('query_vars','wp_insertMyRewriteQueryVars');
       add_filter('init','flushRules');
   
       // Remember to flush_rules() when adding rules
       function flushRules(){
           global $wp_rewrite;
           $wp_rewrite->flush_rules();
       }
   
       // Adding a new rule
       function wp_insertMyRewriteRules($rules)
       {
           $newrules = array();
           $newrules['(galleria)/(.*)$'] = 'index.php?pagename=gallery&galleryname=$matches[2]';
           return $newrules + $rules;
       }
   
       // Adding the id var so that WP recognizes it
       function wp_insertMyRewriteQueryVars($vars)
       {
           array_push($vars, 'galleryname');
           return $vars;
       }
       ```
   
 * WordPress 2.9.2 both in my local test environment, and on the running online 
   server. What can cause this behavior?
 * Thanks

The topic ‘Problem with WP Rewrite’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [kemper-boyd](https://wordpress.org/support/users/kemper-boyd/)
 * Last activity: [16 years ago](https://wordpress.org/support/topic/problem-with-wp-rewrite/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
