For a website or web application user to access the website with or without “www” (e.g. techdasher.com or www.techdasher.com) 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} ^www.domain.com
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]