I have the following code in my htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301]
# 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
I avoid editing the automated code by WordPress because the changes may be erased and I’ll have to do it all again. I have another site running the first three lines of code and it’s working perfectly to replace example.com for http://www.example.com. That’s all I really need for this example.com site but still preserving the WordPress properties.
The problem
example.com is not redirecting to http://www.example.com but instead displaying a 301 error.
I’m using the following lines in all my WordPress-Sites before the
# BEGIN WordPress. This should solve your problem. TheL(for last) is the solution