A simple htaccess code to redirect your website from www to non-www or vice versa. It's important concept in SEO because most of the search engine will treat www and non-www as separate website. As a result, you want all the traffics focus on a single domain name, thus, this htaccess code is a good snippet to know.
from non-www to www
RewriteEngine on RewriteCond % ^yourdomain.com [NC] RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
from www to non-www
RewriteEngine on RewriteCond % ^www.yourdomain.com [NC] RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301