RewriteCond %{HTTP_HOST} *!^www*.url\.com [NC]
RewriteRule (.*) http://www.url.com/$1 [L,R=301]]
The above two expressions tells apache to examine the host the visitor is accessing. The exclamation point (!) in front of www.url.com negates the comparison, saying, “If the host IS NOT www.url.om, then perform RewriteRule.” In our case RewriteRule redirects them to www.url.com while preserving the exact file they were accessing in a back-reference.