I have this somewhat working though it’s important to understand the setup.
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/).
Visually here are where the files are referenced…
site1.com/gallery/image.jpg
site2.net/gallery/image.png
gallery/ (PHP code here)
.htaccess
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.
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.
RewriteEngine on
RewriteRule ^[^/]*/gallery/$ gallery/$1 [QSA]
RewriteCond %{REQUEST_URI} !\.(gif|jpg|png)$
RewriteCond %{REQUEST_URI} !.*/(gallery|admin|blog)
RewriteRule !\.(css|js)$ index.php
So how to I capture all directories regardless of depth while maintaining the image file exception please?
Turns out all I needed to do was add the file extensions to the rewrite condition. Also it’s VERY important to note that the rewrite condition must appear before the rewrite rule.