title: mod_rewrite is ignoring rules in subdirectories
body: <p><strong>Wanted rewrite behaviour</strong> (internal rewrite!)</p>
  
  <pre><code>http://&lt;subdomain&gt;.domain.tld/&lt;path&gt; -&gt; /&lt;subdomain&gt;/&lt;path&gt;
  http://www.domain.tld/path/file.php  -&gt; /www/path/file.php
  http://project.domain-tld/index.php  -&gt; /project/index.php
  </code></pre>
  
  <p><strong>Folder structure:</strong></p>
  
  <pre><code>/                        root
      .htaccess
      /www                 www.domain.tld
          index.php
          /www
              file.php
          /foo
              /bar
                  file.php
      /project             project.domain.tld
          index.php
          someRandomFiles
      /somesubdomain       somesubdomain.domain.tld
          index.php
          someRandomFiles
      /anothersubdomain    anothersubdomain.domain.tld
           index.php
           someRandomFiles
  </code></pre>
  
  <p><strong>Full .htaccess</strong></p>
  
  <pre><code># Unicode
  AddDefaultCharset utf-8
  
  # Activate mod_rewrite
  RewriteEngine on
  RewriteBase /
  
  # Subdomains
  #  Extract (required) subdomain (%1), and first path element (%3), discard port number if present (%2)
  RewriteCond %{HTTP_HOST}&lt;&gt;%{REQUEST_URI} ^([^.]+)\.janbuschtoens\.de(:80)?&lt;&gt;/([^/]*) [NC]
  #  Rewrite only when subdomain not equal to first path element (prevents mod_rewrite recursion)
  RewriteCond %1&lt;&gt;%3 !^(.*)&lt;&gt;\1$ [NC]
  #  Rewrite to /subdomain/path
  RewriteRule ^(.*) /%1/$1 [L]
  </code></pre>
  
  <p>My <code>.htaccess</code> seems to work. You can live test it here:</p>
  
  <ul>
  <li><a href="http://test.janbuschtoens.de/" rel="nofollow">http://test.janbuschtoens.de/</a>
  rewrites to <code>/test/</code></li>
  <li><a href="http://www.janbuschtoens.de/" rel="nofollow">http://www.janbuschtoens.de/</a> 
  rewrites to <code>/www/</code></li>
  </ul>
  
  <p>But there is some strange behaviour in subdirectories. <code>mod_rewrite</code> seems to ignore the rule if the first directory in the requested path has the same name as the subdomain itself. For example:</p>
  
  <ul>
  <li><code>http://www.domain.tld/foo/bar/file.php  -&gt; /www/foo/bar/file.php - Fine!</code></li>
  <li><code>http://www.domain.tld/                  -&gt; /www/     - Fine!</code></li>
  <li><code>http://www.domain.tld/www/              -&gt; /www/     - Should be: /www/www/</code></li>
  <li><code>http://www.domain.tld/www/www/          -&gt; /www/www/ - Should be: /www/www/www/</code></li>
  </ul>
  
  <p>For another live test:</p>
  
  <ul>
  <li><a href="http://test.janbuschtoens.de/" rel="nofollow">http://test.janbuschtoens.de/</a> rewrites to <code>/test/</code></li>
  <li><a href="http://test.janbuschtoens.de/test/" rel="nofollow">http://test.janbuschtoens.de/test/</a> rewrites to <code>/test/</code></li>
  </ul>
  
  <p>It seems like the rule gets ignored.</p>