I'm creating an on-the-fly thumbnailing system for any Content management systems and also have encounter an problem using the htaccess file's backreferences only being accesible in the LAST RewriteCond. This needs to utilize digital, presen and png files... and also the crop query string should ideally be optional.

# This doesn't work since you can't get backreferences from TWO conditions ago
#RewriteCond %{REQUEST_FILENAME} (a-zA--Z0-9-).(jpg|gif|png)
#RewriteCond %{QUERY_STRING} w=([0-9]+)&h=([0-9]+)&crop

# Not sure why this one doesn't work!! 
RewriteCond %{REQUEST_BASENAME}?%{QUERY_STRING} (a-zA--Z0-9-).(jpg|gif|png)?w=([0-9]+)&h=([0-9]+)&c=true

# Only forward to thumbnail.php if file doesn't exist
RewriteCond %1-%2-%3-%4-crop.jpg !-f

# If file doesn't exist, send here:
RewriteRule ^.*$ thumbnail.php?name=%1&type=%2&w=%3&height=%4&c=%5

According to this URL:


The htaccess file inspections if the file is available:


Whether it does not is available it RewriteRules user to:


"Crop" is optional, so without them the prior Web addresses seem like this:


The htaccess above doesn't provide a 500 Internal Server Error, but rather a 404 Not Found for this-is-the-image-name.gif. Also, I don't know how you can test what data the variables hold (REQUEST_URI, REQUEST_BASENAME, QUERY_STRING)... it is possible to method to print these to the browser in some way?

Thanks ahead of time for just about any help!