title: Apache mod_rewrite: force www only if not in localhost
body: <p>I have the following in my htaccess to force the www in URLs:</p>
  
  <pre><code>RewriteCond %{HTTP_HOST} !^www\.
  RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
  </code></pre>
  
  <p>How do I only apply this if not on localhost? Is there some sort of if-condition I can put? Right now, I'm getting something like this: <code>http://www.localhost/</code> ... </p>