Here's my snippet that I'm using
RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^/(.*)$ http://www\.%{HTTP_HOST}/$1 [R=301,L]
Someone may ask why I should do that?
The simple answer: SEO
Search engines are crawling the web to indexing content of web pages. So if they discover links to www.example.com they are not seen as a reference to the same content reachable through example.com.
That's all.
Good german resource explains redirection: Automatische Weiterleitung