Support » Fixing WordPress » rewrite and template_redirect

  • Resolved hanifb


    I have used the nicename permalinks for some time and it works like a charm. I use the /%postname%/ structure.

    I have written a plugin that:

    function netwrok_redirect()

    How can i make the rewrite to
    AND make the template_redirect detect the /network tag?

    I’ve tried to resolve the rewrite with:

    function network_add_rewrite_rule($wp_rewrite)
    $new_rules = array('natverk/(.+)' => 'index.php?natverk='.$wp_rewrite->preg_index(1) );
    	$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;

    But it doesnt work.

Viewing 3 replies - 1 through 3 (of 3 total)
  • joshbauguss


    well, I just went through a day of trying to figure this out. I finally had my eureka moment.

    the BIG thing you are missing. You must let wordpress know about your query variables or it will not grab them.

    add_action(‘query_vars’, ‘yourqueryaddfunction’);

    function yourqueryaddfunction($qvars) {
    $qvars[] = ‘network’;
    return $qvars;

    and per your code above, you would need add_action(‘template_redirect’,’miljo_redirect’);
    to be

    not sure if you had some typos or just cut and paste issues.



    also, i think this is more efficient. I got this tidbit from jerome’s tag keyword plugin.

    in an init function for your plugin (make sure to hook it in)

    global $wp_redirect;
    add_action(‘generate_rewrite_rules’, ‘myrewriterulefunction’);

    doing that i think ensures that it only runs when necessary. (on the permalink option page) Otherwise you run the risk of updating the permalinks every page load which would be bad.

    I think I understand that right at least.

    Thank you both! Worked perfect!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘rewrite and template_redirect’ is closed to new replies.