Redirect www to non-www:

RewriteEngine On
RewriteBase /
RewriteCond % ^www.yourdomain.com [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301

Redirect non-www to www:

RewriteEngine On
RewriteBase /
RewriteCond % ^yourdomain.com [NC]