title: mod_rewrite file exists and regex condition together
body: <p>I have a rewrite directing requests from dir/ to dir/app/webroot/</p>
  
  <p>The problem is, in dir/app/webroot I have the following condition:</p>
  
  <pre><code> RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^(.*)$ index.php [QSA,L]
  </code></pre>
  
  <p>This is saying the files don't exist creating an endless loop because it can't find index.php.  I believe the problem is it is searching for dir/app/webroot/<strong>dir</strong>/index.php instead of dir/app/webroot/index.php in the !-f condition.</p>
  
  <p>How can I manipulate the URI in the condition with a regex like: ^dir/(.*)$ so I can use only page (what is after dir/) to correct the path?</p>
  
  <p>What I have so far is:</p>
  
  <pre><code> RewriteCond %{REQUEST_URI} ^/dir/(.*)$ [NC]
   RewriteCond %{DOCUMENT_ROOT}/dir/app/webroot/%1 !-f
   RewriteRule ^(.*)$ index.php [QSA,L]
  </code></pre>
  
  <p>This fixed the endless loop but now it is always redirecting to index.php.   Do you see where I made a mistake?</p>