title: .htaccess RewriteCond for images in another folder
body: <p>Yes, yet another RewriteCond, but I'm pulling my hair out trying to get it to work....</p>
  
  <p>I have the Apache root as <code>/var/www/html/</code>, and and if I go to <code>http://example.com/</code> it correctly uses <code>/var/www/html/index.php</code>.</p>
  
  <p>Now, the problem is that I have the images in <code>/var/www/images/example.com/</code>.  This is because I have a multi-site setup that needs to be dynamic.  PHP will sort out which site's code is used, so moving the images or aliasing them is not an option as it needs to be dynamic.</p>
  
  <p>So, I have something like this in my <code>/var/www/html/.htaccess</code>:</p>
  
  <pre><code>Options -MultiViews -Indexes
  
  RewriteEngine on
  
  RewriteCond /var/www/images/example.com%{REQUEST_URI} -f
  RewriteRule ^(.+)$ /var/www/images/example.com/$1 # &lt;--- this DOES fire when the image exists
  
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /var/www/html/test.php?file=%{REQUEST_FILENAME} [END]
  </code></pre>
  
  <p>The <code>test.php</code> just echos <code>$_GET</code>, and the strange thing is that <code>$_GET['file']</code> is <code>/var/www/html/var</code></p>
  
  <p>What am I doing wrong?!</p>
  
  <hr>
  
  <h1>Update</h1>
  
  <p>Ok, so now I have this:</p>
  
  <pre><code>RewriteCond %{REQUEST_URI} !^/sites/
  RewriteRule ^(.*)$ sites/%{HTTP_HOST}/$1 [NC]
  
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule . index.php
  </code></pre>
  
  <p>I changed it so that the site files are inside the main server root.  Now I can't get it to not allow direct access to the files.</p>
  
  <p>What I want is this:</p>
  
  <p><a href="http://example.com/images/fb.png" rel="nofollow">http://example.com/images/fb.png</a> -> /var/www/sites/example.com/images/fb.png
  <a href="http://example.com/sites/example.com/images/fb.png" rel="nofollow">http://example.com/sites/example.com/images/fb.png</a> -> /var/www/index.php (to show 404)
  <a href="http://example.com/whatever" rel="nofollow">http://example.com/whatever</a> -> /var/www/index.php</p>
  
  <p>As you can see, the second line file is the full-direct path to the file, and <strong>should pass off to index.php</strong>, but instead it just sends the file.  How to I prevent this?</p>