I want to achieve my /assets/img urls are rewritten to a specific location when that file exists, but otherwise to a php script. Therefore I have these rules:
RewriteCond %{DOCUMENT_ROOT}assets/img$1/.$2.$4/$3.$4 -f
RewriteRule ^assets/img(.*)/([a-zA-Z0-9-_\.]*)\.([^/]+)\.([a-z]{2,4})$ assets/img$1/.$2.$4/$3.$4 [NC,QSA]
RewriteRule ^assets/img(.*)/([a-zA-Z0-9-_\.]*)\.([^/]+)\.([a-z]{2,4})$ assets/img/image.php?path=$1&file=$2.$4&key=$3 [NC,L,QSA]
Nevertheless, the RewriteCond and first RewriteRule don't seem to work. I always get pointed to the php script.
For example, I test this url but see the output of the php script
/assets/img/image.small.png
Then I test if the location of the first RewriteRule works, and see the image I want to have:
/assets/img/.image.png/small.png
My only conclusion is Apache cannot determine if the file exist. How can I make this happen?