title: Rewrite <sub>.domain.com/<path> to /subdomains/<sub>/<path>
body: <p>I've got stuck with my mod_rewrite (for about 4 hours, yes, I googled, too).
  Basically I want to create dynamic subdomains. So I just create a new folder and it automatically has it's own subdomain. Let me give you an example:</p>
  
  <pre><code>/ (root)
      /logs
      /configs
      /otherPrivateStuff
      [...]
      /subdomains (This is, where things get interesting)
          /www            (should be: www.domain.com) [domain.com is automatically 301 to www]
          /aproject       (should be: aproject.domain.com)
          /anotherproject (should be: anotherproject.domain.com)
  </code></pre>
  
  <p>My .htaccess looks like this:</p>
  
  <pre><code># Mod Rewrite
  RewriteEngine on
  
  # Subdomains
  RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com(:[0-9]+)? [NC]
  RewriteRule ^(.*) subdomains/%1/$1/ [NS,L]
  </code></pre>
  
  <p><a href="http://project.domain.com/path/subpath/file.txt" rel="nofollow">http://project.domain.com/path/subpath/file.txt</a> --> <a href="http://domain.com/subdomains/project/path/subpath/file.txt" rel="nofollow">http://domain.com/subdomains/project/path/subpath/file.txt</a></p>
  
  <hr>
  
  <p>This works like a charm, but there is a problem: this rule does not apply, if the url looks like this: <a href="http://project.domain.com/subdomains/" rel="nofollow">http://project.domain.com/subdomains/</a> This beahaves like there's no rewriting at all.</p>
  
  <p>I do not understand this. Can anybody out here help me? :)</p>