Forcing or eliminating the WWW
Posted: Sat Nov 28, 2009 6:24 pm
If you want your website to always use the WWW. prefix (like https://robot.lk) then this htaccess code is your answer. You may want to force the WWW because you like it that way, or because you want consistency for search engines. What ever the reason, use this htaccess code and you will always have the WWW domain prefix used for your website.
The way this works is if the domain name does not start with WWW then the request is rewritten with the WWW. The WWW is really just treated as any other subdomain. So if you have other subdomains (like sub.robot.lk) where you do not want the WWW added (converted to http://www.sub.robot.lk), then you need to include another RewriteCond line for each one.
Or if you want to always eliminate the www prefix, use this htaccess code.
Code: Select all
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Or if you want to always eliminate the www prefix, use this htaccess code.
Code: Select all
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]