Canonical
Redirecting Canonical Hostnames:
To redirect any requests that does not start with www. to make sure they include the www. use the following in your .htaccess file.
Add the following directive:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.net$ [NC]
RewriteRule ^(.*)$ http://www.yourdomain.net/$1 [R=301,L]
Note : Replace yourdomain and extension to your domain name
To redirect to non www page use the following :
Add the following directive:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.yoursitehere.net/$ [NC]
RewriteRule ^(.*)$ http://yoursitehere.net/$1 [R=301,L]
Quite often you will find that the forced usage of the www will cause login problems in lower directories. Then another .htaccess file is required in the lower directory to exclude the 3 www.