WordPress.org

Ready to get started?Download WordPress

Forums

WP_Rewrite Adding rules. (1 post)

  1. Jedtek
    Member
    Posted 1 year ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic