1

I'm having a problem where Wordpress is periodically and randomly destroying the .htaccess file and setting it to zero bytes. When it does this, the site of course breaks until permalinks are manually flushed and .htaccess is rewritten. How can I protect the .htaccess file completely (total read only) or otherwise prevent Wordpress from ever automatically overwriting it? My FTP client won't allow me to set the permissions lower than 644 so I can't make it true read only.

0

3 Answers 3

2

Fixed this by changing permission on .htaccess to 444 from CPanel's file manager. For some reason my FTP client - even though logged in as the same CPanel user - could not make the change and the file would always revert back to 644. Cpanel had no such problem at all.

0

Normally WordPress does only affect rules between # BEGIN WordPress and # END WordPress, rules before or after this section should be left alone.

Basic example from the codex htaccess entry:

### custom rules

# 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

### custom rules

You can find some important functions in /wp-admin/includes/misc.php, like save_mod_rewrite_rules() and insert_with_markers(). The compilation of rules is done by WP_Rewrite.

8
  • I was afraid I'd get an answer like this, though I appreciate the attempt. This issue has nothing to do with WP writing the permalinks, the issue is that the entire htaccess file is being nuked and will suddenly be zero bytes. So I need to keep WP from being able to touch the file at all, not just deal with custom rules. There actually are no custom rules at all.
    – JVC
    Commented May 16, 2015 at 18:43
  • You need to find the reason for that behaviour, because it isn't standard for WP, and thus abnormal. @JonathanvanClute Commented May 16, 2015 at 18:46
  • Right, and I've as yet been completely unable to identify any reason. I'm confident it's not plugin related, and the theme is 100% custom and there is certainly no code within it that would nuke htaccess. So in the meantime since this is a client site that really can't just keep randomly going down, I'm looking to keep it from being possible for WP to touch htaccess.
    – JVC
    Commented May 16, 2015 at 18:50
  • Firstly, what you are trying to do isn't a solution. Secondly, there isn't even an indication that this is done by WP, as this isn't normal behaviour. Thirdly, could be something with the server setup. Last but not least, look further, so you can really solve the problem, instead of just fixing it, you owe it to your client. Just my opinion about it though.. @JonathanvanClute Commented May 16, 2015 at 19:05
  • I am trying to figure out the root cause. But in the meantime, the client is freaking out that their site keeps going down and naturally blaming me and my team's work since they don't understand the technicals. I believe this is likely a lower level server issue, not a WP issue, but to at least prove that 100% I need a way to ensure that WP cannot touch the htaccess file. If you have any actual answers to the question being asked, I would really appreciate hearing them. But lecturing me definitely isn't helpful.
    – JVC
    Commented May 16, 2015 at 19:09
0

My issue was: no matter what I do, .htaccess in my public_html was being created with 444 permissions and the code which was breaking the wp-admin.

How I solved: under wp-includes, I found htaccess.txt and deleted it. Then I deleted .htaccess under public_html

Then after reloading the wp-admin page, issue was resolved :)

1
  • As a general rule, modifying anything in the "core" of WordPress in wp-admin or wp-includes is inadvisable and may result in unexpected behaviors or breaking your site. In this case however, wp-includes/htaccess.txt is not a core file, and should not have been there in the first place.
    – bosco
    Commented Jan 28, 2021 at 15:55

Your Answer

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

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