How to redirect non-www to www using htaccess (Vice versa)


For a website or web application user to access the website with or without “www” (e.g. or for same page. It will be consider as “duplicate content”. Due to this website rank to be drop.

The advantage of redirecting a website

-> An unique website url avoid to split the page rank.
-> Website url is consistent.
-> Avoid content duplicate in search engine (Goolge, Bing, Yahoo, etc.)

Redirecting from non-www to www

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Redirecting from non-www to www (not preferred)

RewriteEngine On
RewriteCond %{HTTP_HOST} ^
RewriteRule ^(.*)$$1 [R=301,L]

Leave a Reply