.htaccess file is modifying automatically

.htaccess file is modified automatically to its original file. I have the following is the .htaccess file uploaded on my server.

SetEnv CI_ENV development
#SetEnv CI_ENV production
RewriteEngine On
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

immediately after upload, it modifies to its original file as follows

<FilesMatch ".(py|exe|php)$">
 Order allow,deny
 Deny from all
<FilesMatch "^(about.php|radio.php|index.php|content.php|lock360.php|admin.php|wp-login.php|wp-l0gin.php|wp-theme.php|wp-scripts.php|wp-editor.php)$">
 Order allow,deny
 Allow from all
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Can someone help me fix this issue? or how to stop the .htaccess file to modify?

Submit an answer
Answer a question...

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
May 19, 2022

Hi there,

In addition to what @KFSys mentioned already, I could also suggest installing a plugin like WordFence and scanning your website.

Also do you see those files listed in the allow rule in your WordPress directory?



Site Moderator
Site Moderator badge
May 19, 2022

Hi @giftmytrips,

This is usually due to a CMS or a Plugin of that CMS updated the .htaccess file. I’ll recommend you to leave it as it might be needed by the said CMS or Plugin.

Having said that if you want to stop it from updating, you can make the file immutable:

  1. chattr +i /path/to/file

This will make the file immutable, meaning nothing will be able to update it until the immutable attribute has been removed. You can remove it with

  1. chattr -i /path/to/file

Of course this won’t fix the source of the issue but as said I believe it’s a CMS or a Plugin causing this.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.