title: .htaccess rewrite all subdomains to directories of the same name
body: <p>I have a directory for every sub-domain and I want to be able to add more automatically without making a rule for each one.</p>
  
  <p>For example when I go to <a href="http://sub.domain.com/index.html" rel="nofollow">http://sub.domain.com/index.html</a> it should serve the file /sub/index.html without redirecting the browser.</p>
  
  <p>This is what I've got and it's not working:</p>
  
  <pre><code>RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com
  RewriteRule ^(.*)$ /%1/$1
  </code></pre>