Code:
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
# disable magic quotes
php_flag magic_quotes_gpc Off
# disable register globals
php_flag register_globals 0
# pass resources/images/* through, though first convert ?w=x&h=x
# if the file doesn't exist with the proper dimensions, then just skip
# and let the dispatcher deal with it
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} w=([0-9]+)&h=([0-9]+)
RewriteCond resources/$1/$2.$3%1%2 -f
The file exists check is made against the {REQUEST_FILENAME} string which is the PHYSICAL path/file whereas you are using the webspace path. I believe (without checking) that you can get the equivalent of the {REQUEST_FILENAME} by preceding resources with %{DOCUMENT_ROOT}.
Then, I believe that the $ variables do not exist at this point (but I've recently seen an apache.org code snippet that indicates I'm wrong - I have more checking to do on this one, too.
RewriteRule ^resources/([a-z\-\_]+)/([a-z\-\_]+)\.(a-z)$ resources/$1/$2.$3%1x%2? [L]
The range definition is wrong BECAUSE the hyphen MUST be either first (preferred) or last to NOT be interpreted as part of a range definition, i.e., a-z. Escaping it does NOTHING - as it's irrelevant to the underscore character. Change these two [a-z\-\_] snippets to [-a-z_] and you should have better success (when the preceding RewriteCond "problems" are addressed).
# publicly accessible resources/images folder
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond $0 ^(images/(.+))$
RewriteRule ^images/(.+)$ resources/images/$1
# publicly accessible webroot/images folder
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond $0 ^(images/(.+))$
You've GOT me on this one! Beside the forward "backreference," you're using an Apache variable that I know exists but I've not found a reference for how it's created (what it is). $1-$9 are the ordered atoms but $0 is WHAT? If you know where that's defined, please let me know (for my own piece of mind).
RewriteRule ^images/(.+)$ webroot/images/$1
NO Last flag directs mod_rewrite to place an AND here so, with the conflicting regex, the third block can NEVER match/redirect. It's a simple error (along the lines of a typo) but, OH SO CRITICAL!
# redirect everything to the dispatcher, everything!
#RewriteCond %{ENV:REDIRECT_STATUS} ^$
#RewriteRule ^(.*)$ dispatcher.php [QSA,L,NC]
I REALLY like the use of the environment variable to prevent looping - especially when using the
Bookmarks