Why does WordPress 3.0.4 keep deleting the contents of the .htaccess file?

I just installed WordPress 3.0.4 on a GoDaddy hosted server. And I’ve been having a problem with my .htaccess file. For some reason, WordPress automatically erases all the mod_rewrite configuration settings in .htaccess file whenever I view the WP admin page for setting permalinks. Deleting the .htaccess file kinda defeats the purpose of that page.

I’ve been able to do create a workaround by just manually entering the configurations into the .htaccess file and never visiting the permalink configuration page. But this doesn’t feel like a good solution.

Read More

Can anyone share thoughts about what might be causing this?

Thanks!
David

Related posts

Leave a Reply

3 comments

  1. Something else is going on here. WordPress does not erase the contents of the .htaccess file when it writes new permalinks; it appends the new permalink structure to the end of the file.

    Do you have anything other code or plugins that uses .htaccess? Are you on a Windows server that does not natively support mod rewrite and as a result requires other ways of enabling mod rewrite and might be the cause of the erasing?

    If you want to keep WP from writing/appending to the .htaccess file, set permalinks, make your own changes, and then set .htaccess permissions to 444, and then you can view the permalinks admin page without WP automatically appending to the file. This is what I do.

  2. WordPress always tries to write the .htaccess file when you visit the Permalinks page, even when there is nothing to write (to make sure that old rules don’t stay around). This happens in save_mod_rewrite_rules(), which is called from $wp_rewrite->flush_rules() if the $hard parameter is true.

    Everything that is between the # BEGIN WordPress and # END WordPress lines is the output of $wp_rewrite->mod_rewrite_rules(). Looking at that function, there are only a limited number of cases when it would return nothing:

    • $wp_rewrite->using_permalinks() returns false, which is the case if the permalink structure is empty (if permalinks are disabled)
    • the mod_rewrite_rules or rewrite_rules return nothing. This can happen if a plugin thinks they are actions and not filters, and thus forgets to return anything.

    I would try calling $wp_rewrite->mod_rewrite_rules() and see what it returns.

  3. Thank you @Jan … solved a weeklong problem of mine! .htaccess kept getting overwritten (actually corrupted and bloated with repetitive WP settings) .. thought it was my caching plugin but discovered it is my functions.php where I set up custom taxonomy and use flush_rewrite_rules(); … setting it to flush_rewrite_rules( false ); makes it a ‘soft flush’ according to WP Codex and this solves my htaccess problem! A hundred blessings to you