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:

this-is-the-image-name.gif?w=200&h=100&c=true

The htaccess file inspections if the file is available:

this-is-the-image-name-gif-200-100-crop.jpg

Whether it does not is available it RewriteRules user to:

thumbnail.php?name=this-is-the-image-name&type=gif&w=200&height=100&c=true

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

this-is-the-image-name.png?w=200&h=100
this-is-the-image-name-png-200-100.jpg
thumbnail.php?name=this-is-the-image-name&type=png&w=200&height=100

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!