title: How to rewrite domain.com to www.domain.com
body: <p>I am trying to edit <code>apache2.conf</code> to rewrite domain.com to www.domain.com:</p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
      Options +FollowSymlinks
      RewriteEngine On
  
      # if request is not for a file/directory 
      RewriteCond %{SCRIPT_FILENAME} -d [OR]
      RewriteCond %{SCRIPT_FILENAME} -f
      # then skip from rewrites
      RewriteRule ^ - [L]
  
      # add www to hostname
      RewriteCond %{HTTPS} !=on
      RewriteCond %{HTTP_HOST} !^www\. [NC]
      RewriteCond %{SERVER_ADDR} !=127.0.0.1
      RewriteCond %{SERVER_ADDR} !=::1
      RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  
      # forward all the requests to `/index.php
      RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>I can't see any obvious errors, but the rewrite doesn't work. Any ideas?</p>