WordPress.org

Support

Support » Plugins and Hacks » Hacks » WP_Rewrite Adding rules.

WP_Rewrite Adding rules.

  • Hi,

    I am trying to add a rule that catches every request after the other internal WP rules have not matched (e.g. at the bottom of everything).

    The code I am trying is below.

    add_rewrite_tag('%c%','([^&]+)');
    	add_rewrite_rule('^([^/]*)', '/?page_id=' . $old_id . '&c=$matches[1]', 'bottom');
    	global $wp_rewrite;
    	$wp_rewrite->flush_rules();
    	print("<pre>");
    	print_r($wp_rewrite->rules);

    This code runs, but instead of the rewrite rule ending up on the internal rewrite_rules option in the database, it ends up writing a rule to the .htaccess, which of course then breaks all the URLs on the site as it catches everything.

    My understanding from the docs is add_rewrite_rule() adds it to the db rewrites?

    Thanks!

  • The topic ‘WP_Rewrite Adding rules.’ is closed to new replies.
Skip to toolbar