Title: Rewrite API Not Working
Last modified: January 7, 2023

---

# Rewrite API Not Working

 *  [wpbroken2much](https://wordpress.org/support/users/wpbroken2much/)
 * (@wpbroken2much)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/rewrite-api-not-working/)
 * I just created my first rewrite rule using the WordPress Rewrite API but it does
   not work.
 * The code runs in the activation hook of a plugin and reads as follows:
 *  add_rewrite_rule(‘redirect/([0-9]+)/?’, ‘wp-content/plugins/redirect/source/
   index.php?urlid=$matches[1]’, ‘top’);
    flush_rewrite_rules();
 * This successfully adds the rewrite rule to the .htaccess file as:
 * RewriteRule ^redirect/([0-9]+)/? /wordpress/wp-content/plugins/myplugin/redirect/
   index.php?urlid=$matches[1] [QSA,L]
 * This should result in a page getting the urlid, looking up the url, and doing
   a 302 redirect but instead I get a 404 error page from WordPress.

Viewing 1 replies (of 1 total)

 *  Thread Starter [wpbroken2much](https://wordpress.org/support/users/wpbroken2much/)
 * (@wpbroken2much)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/rewrite-api-not-working/#post-16349556)
 * I tried adding urlid as a query variable but that does not seem to work. To make
   matters worse I cannot find where WP stores query variables in the database so
   I cannot check to see if I am adding it right.
 * I added this both inside and outside my activation function. Neither fixes the
   problem.
 *     ```
       function add_custom_query_var( $vars ){
             $vars[] = "urlid";
             return $vars;
         }
         add_filter( 'query_vars', 'add_custom_query_var' );
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Rewrite API Not Working’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [wpbroken2much](https://wordpress.org/support/users/wpbroken2much/)
 * Last activity: [3 years, 5 months ago](https://wordpress.org/support/topic/rewrite-api-not-working/#post-16349556)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
