0

I have a plugin which manages redirects for after another theme has been deactivated. It helps SEO obviously.

I have the below wrapped in a function employed by 'after_switch_theme' hook.

    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();   

What is strange though is that at random times my htaccess file is getting ruined. I'm not sure why this is.

Perhaps there is a fault in the above, but really I just have to ensure that the proper post is called from the former structure, which in turn calls the redirect. Without the above rewrite, the old post isn't found when the URL is visited.

Is there a better "best practice" or a correction on the above for this scenerio?

4
  • htaccess file has virtually nothing to do with wordpress "rewrite" (horribly misleading name) rules. Apr 26, 2015 at 6:04
  • I'm pretty sure this is sabotoging my htaccess though right? Somewhere down the trail? Maybe the rewrite causes wordpress or another plugin to alter the htaccess? I say this because my htaccess randomly corrupts itself. I suspecct this is it.
    – 1Up
    Apr 26, 2015 at 6:09
  • If your htaccess is writable by the webserver then you are doing it very wrong. Apr 26, 2015 at 6:32
  • Not sure...lots of plugins change htaccess...caching plugins, etc.
    – 1Up
    Apr 26, 2015 at 6:58

0

Your Answer

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

Browse other questions tagged or ask your own question.