最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

permalinks - How to protect htaccess so it can't be overwritten?

programmeradmin3浏览0评论

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.

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.

Share Improve this question edited Jun 20, 2016 at 13:36 cjbj 15k16 gold badges42 silver badges89 bronze badges asked May 16, 2015 at 17:44 JVCJVC 4711 gold badge9 silver badges20 bronze badges 0
Add a comment  | 

3 Answers 3

Reset to default 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.

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.

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 :)

发布评论

评论列表(0)

  1. 暂无评论