Background: I've recently created a dynamic image resizing script in PHP so that I can give it an image path somewhere within the server + get parameter of width, and it'll return this image, resized according to the query parameter and throw the image into a cache folder for future use.
Afterwards, if the same image, with the same width is requested, it goes to that PHP script, and the script checks if the file already exists, and if it does, it'll just output it. (It will do file_get_contents(), and then echo it with the appropriate header)
The challenge:
What I want to do is to bypass the PHP script if the file already exists. I want .htaccess to check if the file exists in the cache folder, and then simply go to that file, instead of the PHP script. That would be simple enough, except the filename includes the modified width.
So, for instance:
If the file relative path is images/products/36sh542dhs.jpg, and I want it modified with width 100px, the request URL will look like this si/images/products/36sh542dhs.jpg?d=100. The file will be stored as follows: resized_images/cache/images/products/36sh542dhs---D100.jpg.
Is there any conceivable way to get .htaccess to take in si/images/products/36sh542dhs.jpg?d=100, break it up, remove si, add resized_images/cache instead, AND modify the filename to stick the D---100 right before the "dot extension" part?