Title: url rewrite
Last modified: August 20, 2016

---

# url rewrite

 *  Anonymous User
 * (@anonymized-8890968)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/url-rewrite-7/)
 * why i can’t get this work. url like [http://wordpress.org/myvar/test-page/](http://wordpress.org/myvar/test-page/)
   works perfect with such linein .htaccess RewriteRule ^([a-z]{0,4})/(.?.+?)/$ /
   index.php?myvar=$1&pagename=$2&%{QUERY_STRING} [NC]
 * But doesn’t it have actually to be done with this:
 *     ```
       function do_rewrite()
       {
       	add_rewrite_tag( '%myvar%', '^([a-z]{0,4})' );
           add_rewrite_rule( '^([a-z]{0,4})/(.?.+?)/$', 'index.php?myvar=$matches[1]&pagename=$matches[2]', 'top' );
       }
       add_action('init', 'do_rewrite');
       ```
   
 * The problem is that i can’t get it working without modifying .htaccess.
    The 
   permalink structure is /%myvar%/%postname%/

The topic ‘url rewrite’ is closed to new replies.

## Tags

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

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 0 replies
 * 1 participant
 * Last reply from: Anonymous User
 * Last activity: [14 years, 3 months ago](https://wordpress.org/support/topic/url-rewrite-7/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
