简体   繁体   中英

Root .htaccess file being overwritten in Wordpress

I am not sure if there is something wrong with my .htaccess file but I've been noticing recently that it is being overwritten. It is in the root folder of the website directory. This is what I have in my .htaccess :

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^mysite\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 week"
ExpiresByType image/jpeg "access 1 week"
ExpiresByType image/gif "access 1 week"
ExpiresByType image/png "access 1 week"
ExpiresByType text/css "access 1 week"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 week"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 week"
</IfModule>
## EXPIRES CACHING ##

# 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

After being overwritten, I am left with this:

# 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

How do I prevent this from happening? The site is on a shared hosting.

Additional information (15 Jan 2016): I have a copy of the website on the staging site with same plugins. There are just a few plugins that are different on the live site. Otherwise they are pretty identical.

On the live site, today I discovered the .htaccess file is updated every few seconds. I logged in to FTP and every time I refresh the directory, I see the Last Modified time changed. I added the above code again and refreshed the directory every few minutes. It kept changing the Last Modified time but the content did not change. I think it completely overwrites the content once every few weeks or so. That's probably what happened but I don't know why. Anyway I also changed the file permission from 644 to 444. After doing this, the Last Modified time has not changed on every refresh. I will keep an eye on this and check again in a few days.

Could it be the issue in the hosting provider's end? There is nothing in the logs that indicate anything useful.

Did you update the post format? Normally , it would add the information to .htaccess instead of re-creating it , but it might be happening. Another guess is as @joe suggested : Try to disable your plugins to see what happens.

Lastly , you can make .htaccess read only using permissions. If you need help with permissions , this is a good place to start : http://www.december.com/unix/ref/chmod.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM