When user is visiting by www.domain.name
, redirect to domain.name
.
Put this in an .htaccess
file in your root directory of your website:
RewriteEngine On
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^domain\.name
RewriteRule (.*) http://domain.name/$1 [R=301,L,QSA]
This is what they do, in order:
HTTP_HOST
was providedwww
or any other sub domain, then allow the rewrite to continue. This prevents an endless redirect back to itself.(.*)
, including the querystring QSA
, and redirect R=301
to the correct domain. The L
just says this is the last command in the file if a match is found.