Thursday, November 6, 2008
non-www v/s www and 301 redirect
Many know that canonical domains can have a some impact on your site and it could be solved within moments with a few lines of code in the .htaccess file on an Apache Linux server.

Just a few lines of code like shown below:
first Url rewrite needs to be turned on with this line
RewriteEngine onthen to redirect all users to access the site WITH the 'www.' prefix (http://example.com/... will be redirected to http://www.example.com/...)
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]or to redirect all users to access the site WITHOUT the 'www.' prefix (http://www.example.com/... will be redirected to http://example.com/...)
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]