Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]
You might want to set an exclusion rather than an inclusion, otherwise
http://somethingelse.domain.com/ would still fall through.