The following code will redirect non-www to www e.g xyz.com to www.xyz.com

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