Ive got a image cache system that im using to generate certain image sizes as require. Im using modrewrite to check for the file and call the image creation system if it doesnt exist. The problem im having is that it is calling the image creation system even if the image does exist!
The modrewrite is simple enough (sites in the images sub directory)
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /images/index.php?id=$1 [L,QSA]
I even tried removing the -d incase the directory check was confusing it. Ive now got it so that it checks the file exists inside the index.php code – which reports that it does.
I use the url images/cache/140x20/Test.JPG in the html – the file exists, so the RewriteCond should not call the index.php code – but it does for some reason?
Im sure its something obvious but i just cant figure it out
That’s weird. I was testing under a subdirectory and was getting some unexpected values for
%{REQUEST_FILENAME}. But I was able to get the check to work correctly by reconstructing from the document root. Maybe my understanding of%{REQUEST_FILENAME}or the underlying mechanism apache uses to make URI-path to file-path is different than what I expected.Try:
EDIT:
If your extensions are in all caps but the image filename extensions are always all lowercase, you can use a RewriteMap and define a map using the
tolowerfunction:(somewhere in your server or vhost config:
Then in your htaccess file (above your other rules), change the filenames to lowercase:
You can also do something similar with the entire filename, or the entire path.