Redirecting www.domain.com to domain.com

There are a lot of examples how to redirect http://domain.com to http://www.domain.com, but not the other way around.
So without further ado, this is what to put in your .htaccess file, if you want a site hosted by apache to redirect all URLs that start with www to the non-www variant:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*) http://%1/$1 [R=301]

Update: Anne just reminded me that what I wrote above is actually wrong.
I did find examples of how to do the opposite, but they all required you to write the absolute URL, which I didn’t want, because it requires me to have a different .htaccess file on my local test server, from the one I have on meidell.dk.
The code above just turns any www. url into non-www.