0

This seems to be modding my .htaccess with every page view. What is the standard way of setting up a rewrite? This is what I have so far:

if(!function_exists('some_rewrite')){
    add_action( 'init', 'replacement_rewrite' );
    function replacement_rewrite( )
    {    
        global $wp_rewrite;
        $wp_rewrite->add_permastruct('typename','typename/%year%%postname%/' , true , 1);
        add_rewrite_rule('typename/([0-9]{4})/(.+)/?$','index.php?typename=$matches[2]', 'top');
        $wp_rewrite->flush_rules();
    }
}
1

See flush_rules in Codex:

Because this function can be extremely costly in terms of performance, it should be used as sparingly as possible - such as during activation or deactivation of plugins or themes. Every attempt should be made to avoid using it in hooks that execute on each page load, such as init.

Only flush rules when they change, not on every page load.

1
  • Thanks much. I didn't know the flush-rules thing. I can't even remember them with my wife reminding me...now wordpress?
    – 1Up
    Apr 22 '15 at 2:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.