Here's a quick guide on how to redirect to www and non-www using .htaccess:
To redirect to www:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
To redirect to non-www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Simply add the appropriate code to your website's .htaccess file to apply the redirection.
See also: How to edit .htaccess