• Resolved hanifb

    (@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:

    add_action('template_redirect','miljo_redirect');
    
    function netwrok_redirect()
    {
    if(isset($_GET['network'])
    	{
    		include(TEMPLATEPATH."/network.php");
    		exit();
    	}
    }

    How can i make the https://www.wordpressblog.com/?network rewrite to https://www.wordpressblog.com/network/
    AND make the template_redirect detect the /network tag?

    I’ve tried to resolve the rewrite with:

    add_action('generate_rewrite_rules','network_add_rewrite_rule');
    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)
  • jbauguss

    (@joshbaugussnet-1)

    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
    add_action(‘template_redirect’,’netwrok_redirect’);

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

    jbauguss

    (@joshbaugussnet-1)

    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;
    if(isset($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.

    Thread Starter hanifb

    (@hanifb)

    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.