• 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

    (@wpbroken2much)

    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.