Rewriting main domain to subdomain (mod_rewrite)

I think you're missing something in your RewriteCond line. Try this:

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

So add the %{HTTP_HOST} into your RewriteCond rule... Note that I haven't tested this, so please post the results...