Always use www in hostname

From Servage Wiki
Jump to: navigation, search

Please note that all contributions to Servage Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here. You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Servage_Wiki:Copyrights for details). DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION!

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]

Another alternative

Most hosting sites redirect everything to your main domain that is not an explicit real virtual host subdomain. They use a wild-card like: *.yourdomain.com to send not only http://yourdomain.com/ and http://www.yourdomain.com/ but every other subdomain name to your site. So to force everyone to go to http://www.yourdomain.com you can also use a ! (=NOT) in the RewriteCond like this:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]

OR if you do not want the www in front of your domain name, just do:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^yourdomain.com [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]
Personal tools
Navigation