.htaccess文件问题/无法编辑.htaccess

时间:2016-08-19 07:03:46

标签: php apache .htaccess mod-rewrite

我使用GoDaddy托管服务提供商,当我在cpanel中编辑.htaccess时,它会生效,但经过几个小时(有时几天).htaccess恢复默认。我所有的改变都消失了。

我的编辑.htaccess文件:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* ? [F,L]
RewriteCond %{HTTP_HOST} ^xxx\.xxx\.xxx\.xx
RewriteCond %{HTTP_HOST} ^my-domain\.com
RewriteRule (.*) http://www.my-domain.com/$1 [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
#Maintenance Mode
#RewriteCond %{REMOTE_ADDR} !^111\.111\.111\.11
#RewriteCond %{REQUEST_URI} !^/berightback\.html$
#RewriteRule ^(.*)$ http://my-domain.com/berightback.html [R=307,L]


ExpiresActive on

    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"

</IfModule>

# END WordPress

偶然发生了一些奇怪的事情:  1)在浏览器栏中,我的网站始终没有www  2)我的网站的IP不会重定向到我的网站。

但这里的主要问题是为什么.htaccess在我编辑后变为默认设置?

谢谢!

1 个答案:

答案 0 :(得分:2)

这是你的wordpress安装。 #Begin wordress#End Worpress标记内的任何内容都会被wordpress覆盖。您需要删除那些开始和结束注释之外的所有非wordpress规则。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Maintenance Mode
#RewriteCond %{REMOTE_ADDR} !^111\.111\.111\.11
#RewriteCond %{REQUEST_URI} !^/berightback\.html$
#RewriteRule ^(.*)$ http://my-domain.com/berightback.html [R=307,L]"

RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* ? [F,L]
RewriteCond %{HTTP_HOST} ^xxx\.xxx\.xxx\.xx
RewriteCond %{HTTP_HOST} ^my-domain\.com
RewriteRule (.*) http://www.my-domain.com/$1 [R=301,L]

# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

</IfModule>

ExpiresActive on
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month

特别是当您对固定链接进行更改时。 你可以看到其他人有同样的问题。 https://wordpress.org/support/topic/htaccess-file-being-overwritten