Redirect domain.com to www.domain.com

If you want to force clients to use www.domain.com, you can redirect them from domain.com to the www version with an .htaccess file.

In your public_html folder, create a file called .htaccess and add the code:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=permanent]

where you’d need to replace domain\.com and domain.com with your actual domain name.  Note the \ character must be present to escapce the . character.

Other versions of the same thing do a negation check to see if the domain is not www.domain.com, but that doesn’t work if you have subdomains.. hence the need for the explicit check for the value we don’t want.