This will change domain.com
to www.domain.com
:
# Force the "www."
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
How do I replace the "domain" part so that this works on any domain?
This will change domain.com
to www.domain.com
:
# Force the "www."
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
How do I replace the "domain" part so that this works on any domain?
this worked like magic for me
This will do it:
This won't work with subdomains.
domain.com correctly gets redirected to www.domain.com
but
images.domain.com gets redirected to www.images.domain.com
Instead of checking if the subdomain is "not www", check if there are two dots:
This is an older question, and there are many different ways to do this. The most complete answer, IMHO, is found here: https://gist.github.com/vielhuber/f2c6bdd1ed9024023fe4 . (Pasting and formatting the code here didn't work for me)
This redirects
example.com
towww.example.com
excluding subdomains.The following should prefix 'www' to any request that doesn't have one, and redirect the edited request to the new URI.