There should be three entries if we want to use wildcards:
RewriteEngine on
RewriteBase /
#for all requests on mydomain.com
RewriteCond %{HTTP_HOST} mydomain.com$ [NC]
#if they are not for the www.mydomain.com
RewriteCond %{HTTP_HOST} !^www.mydomain.com$ [NC]
#301 redirect to www.mydomain.com
RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]