I found the solution.
Its important you put the lines as the FIRST thing after the mod_rewrite module is loaded.
If you put it after, it will not work.
<IfModule mod_rewrite.c>
############################################
## redirect www to non-www
RewriteCond %{HTTP_HOST} ^
www.domain.com [NC]
RewriteRule ^(.*)$
domain.com/$1 [L,R=301]