If you would like to redirect anything from
http://domain.com to
http://www.domain.com (so the www is always in the URL), you can accomplish this by using the code below. This is helpful in search engine optimization and will help give your site a higher page rank.
I use the first method, but only when I can't edit the httpd.conf file directly.
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# require non-empty HOST header
RewriteCond %{HTTP_HOST} !^$
# require case-insensitive HOST to be www.htaccesselite.com
RewriteCond %{HTTP_HOST} !^www\.htaccesselite\.com$ [NC]
# 301 redirect everything to correct www.htaccesselite.com
RewriteRule ^(.*)$ http://www.htaccesselite.com/$1 [R=301,L]
# or you can use this rewriterule
#RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Code:
RewriteCond %{HTTP_HOST} !^www\.htaccesselite\.com$
RewriteRule ^(.*)$ http://www.htaccesselite.com/$1 [R=301,L]
Code:
RewriteCond %{HTTP_HOST} ^htaccesselite\.com$ [NC]
RewriteRule ^(.*) http://www.htaccesselite.com/$1 [QSA,L,R=301]
Code:
RewriteCond %{HTTP_HOST} !^www\.htaccesselite\.com$ [NC]
RewriteRule ^(.*) http://www.htaccesselite.com/$1 [QSA,L,R=301]
Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\..* [NC]
RewriteRule ^(.*) http://www.%{HTTP_HOST}/$1 [R=301]