1

WordPress keeps writing rewrite rules into .htaccess again and again till it causes an error and causes server to return 500 Internal server error...

i.e. My .htaccess is a series of

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

repeated over and over and over again.

By itself, that's not a massive problem (except that my .htaccess will grow to several MBs, slowing down the site significantly). But occasionally, there would appear some garbage in the .htaccess which takes the site down (500 Internal Server Error)

4

I am not sure why this happens, but you can stop all write access to your .htaccess with a simple filter:

add_filter( 'flush_rewrite_rules_hard', '__return_false' );

Neither WordPress nor any plugins calling flush_rewrite_rules() will write something into the file now. Other methods to access and change the file will still work, for example insert_with_markers().

  • Where should I put this? Into functions or wp-config or somewhere else? – OC2PS Oct 13 '13 at 18:26
  • 1
    In a separate plugin or your theme’s functions.php. See Where do I put the code snippets? – fuxia Oct 13 '13 at 18:30
  • Thanks! Will this filter completely stop WordPress from writing into .htaccess? I ask because at different points some plugins might need to write something to it... – OC2PS Oct 13 '13 at 18:35
  • @OC2PS See my update. Most plugins will still work. – fuxia Oct 13 '13 at 18:39
  • Thanks..packaged the statement up as plugin github.com/OC2PS/wordpress-stop-the-madness/archive/master.zip and installed the plugin. Unfortunately, doesn't seem to have helped. – OC2PS Oct 14 '13 at 13:17
-1

For me just a resetting of WordPress Permalinks fix the problem!

  • Please, explain why and how your post answers the question. At frist reading, it seems not to be related with the problem described in the quesito. – cybmeta Mar 10 '16 at 14:08

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.