Recently, I enforced non-www to www redirection on my website.
I am using this rule in my htaccess file:
RewriteCond %{HTTP_HOST} !^www\\. [NC] Rewrite