Apache .htaccess -how to 301 redirect from a non-WWW to WWW.mysite.com

By donmc, 6 August, 2012

I have had to mess with this way too many times, so just for the record, here is what works for me:
[this based on an Apache/2.2.14 (Ubuntu) system...]

  RewriteEngine on
  # this is for sites using port 80:
  RewriteCond %{HTTP_HOST} ^mysite.com [NC]
  RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]