title: Apache Rewrite: rewrite ONLY index URLs regardless of depth with file extension exceptions
body: <p>I have this somewhat working though it's important to understand the setup.</p>
  
  <p>With multi-domain support (multiple domains using the exact same copy of software) I need to rewrite ONLY the directories (which end cleanly like dir1/ or dir2/).</p>
  
  <p>Visually here are where the files are referenced...</p>
  
  <p><strong>site1.com/gallery/image.jpg</strong></p>
  
  <p><strong>site2.net/gallery/image.png</strong></p>
  
  <p><strong>gallery/</strong> (PHP code here)</p>
  
  <p><strong>.htaccess</strong></p>
  
  <p>So I want to have only directories rewritten to gallery/ while all image files (by extension) are rewritten to the site1/gallery/image.jpg paths.</p>
  
  <p>What I have currently rewrites ONLY the base gallery/ path however it does NOT rewrite deeper gallery indexes (e.g. gallery/my_gallery/) however the image exception does work as well.</p>
  
  <pre><code>RewriteEngine on
  RewriteRule ^[^/]*/gallery/$ gallery/$1 [QSA]
  RewriteCond %{REQUEST_URI} !\.(gif|jpg|png)$
  
  RewriteCond %{REQUEST_URI} !.*/(gallery|admin|blog)
  RewriteRule !\.(css|js)$ index.php
  </code></pre>
  
  <p>So how to I capture all directories regardless of depth while maintaining the image file exception please?</p>