I'm trying create a caching system for an "on demand" PHP image resizer.
I need to be able to check if the following file and query string exists in cache:
https://www.example.com/images/img.jpg?w=400&h=300&fit=crop
My PHP script generates the cached file by replacing all special chars (?,&,=) with underscore.
This is what the cached object looks like:
/cache/images/img.jpg_w_400_h_300_fit_crop
How do I check if the requst + query exists in /cache as file and serve it if it does?
What I currently have that works for files without query vars is this:
# if file exists in /cache/ directory
# serve file from /cache/ directory
RewriteCond %{DOCUMENT_ROOT}/cache/$1 -f
RewriteRule ^(.*)$ /cache/$1 [L,QSA]
I tried with something like this but it doesn't work because I suck at htaccess/regex :)
RewriteCond %{QUERY_STRING} ^(.*)(:?\&|\?|\=)(.*)$
RewriteCond %{DOCUMENT_ROOT}/cache/$1_%1_%2 -f
RewriteRule ^(.*)$ /cache/$1 [L]