Cecily Miller Cecily Miller - 3 months ago 21
Apache Configuration Question

.htaccess file issue / can't edit .htaccess

I use GoDaddy Hosting Provider and when I edit .htaccess in cpanel, it take effect but after couple of hours (sometimes couple days) .htaccess is back to default. All my changes are gone.

My EDITED .htaccess file:

# 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


Couple weird thing happens also:
1) in browser bar my website is always without
www

2) My website's IP do not redirect to my website.

But the main question here is why .htaccess become to the default settings after I have edited it?

Thank you!

Answer

It's your wordpress install. Anything INSIDE the #Begin wordress and #End Worpress tags get overwritten by wordpress. You need to remove ALL non wordpress rules outside of those begin and end comments.

<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

Specifically when you make changes to permalink. You can see others with same issues. https://wordpress.org/support/topic/htaccess-file-being-overwritten