2

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.

Can anyone share thoughts about what might be causing this?

Thanks! David

2
  • Do you have extra rules of your own in your .htaccess files, or only the ones WordPress adds? It does re-write the file when you visit the Permalinks page, so if you have extra rules you should add them via the WordPress API ($wp_rewrite->add_external_rule()). (Use @Jan in your reply and I get a notification)
    – Jan Fabry
    Feb 8, 2011 at 10:03
  • @Jan: No. I just have the standard WordPress rules. The first line of the rules says # BEGIN WordPress and the last line says # END WordPress. It's really strange though. When I visit the Permalinks admin page, WordPress modifies the .htaccess file by getting rid of the rules between # BEGIN WordPress and # END WordPress. WordPress keeps those comments in the .htaccess file though. So ironically, Permalinks don't work after I visit that page.
    – user2052
    Feb 10, 2011 at 12:45

3 Answers 3

4

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
  • Thanks for the reply songdogtech. I just wrote a comment in my original post that provides more detail. FYI, the Permalink page worked fine when the blog was hosted on Yahoo! Small Business web servers. But I migrated the blog to a GoDaddy shared server. After the migration, the Permalink page started acting weird. But I didn't change any plugins after I migrated the site.
    – user2052
    Feb 10, 2011 at 12:47
  • Shared Windows or Linux at GoDaddy? Permalinks ware enabled differently under Windows. And how did you migrate to GD? Feb 10, 2011 at 17:19
1

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.

0

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

1
  • 1
    You should never flush the rewrite rules on a continual basis. Instant site slow-downer. Remove that line entirely, and only flush the rules once when you change the taxonomy around. Visiting the Permalink settings page auto-flushes the rewrite rules for you, and you never need to have code do it, really.
    – Otto
    Jan 24, 2012 at 6:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.