title: Rewrite URL from http://example.com/blog/ to http://blog.example.com/
body: <p>What <code>RewriteRule</code> (using <code>.htaccess</code>/<code>mod_rewrite</code>) should I use to redirect <code>http://example.com/blog/</code> (with <code>www</code> or without) to <code>http://blog.example.com/</code> ?</p>
  
  <p>I'm using the following, but getting a redirect loop: </p>
  
  <pre><code>RewriteEngine On
  RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
  RewriteRule ^(.*)$ http://www.example.com/blog/ [L,R=301]
  
  RewriteCond %{HTTP_HOST} www\.example\.com [NC]
  RewriteRule ^(.*)$ http://www.example.com/blog/ [L,R=301]
  </code></pre>