In your home directory (usually httpdocs) create a file labeled:
.htaccess
in it place these lines:
Options +FollowSymlinks
RewriteEngine on
rewritecond %{HTTP_HOST} !^(www\.)MYDOMAIN\.com$ [nc]
rewriterule ^(.*)$ http://www.MYDOMAIN.com/$1 [L,r=301,nc]
Replace "MYDOMAIN" with your actual domain name and save the file. That will send everyone who doesn't first go to www.mydomain.com to www.mydomain.com. For example if they go to:
http://mydomain.comÂ
they will be automatically redirected to:
http://www.mydomain.com
This also works if you have other domain names pointed at your main domain name. For example if myotherdomain.com is pointed to mydomain.com, then when someone visits:
http://myotherdomain.com (with or without the "www")
The will end up on:
http://www.mydomain.com
This can be useful for search engine optimization, since all of your various domains, with or without the "www", will all become one site as far as google or other search engines are concerned. All of your "link juice" will be consolidated into one result, instead of being dispersed over several different sites.
- 22 Users Found This Useful