I have a regular expression in my RewriteRule, which is currently working fine. Secondly I’d like to test wheter the file (where the request is rewritten at) exists. Therefore I placed a RewriteCond before my rule, but it validates always to false, unfortunately.
This is my regex:
assets/img(.*)/([a-zA-Z0-9-_\.]*)\.([^/]+)\.([a-z]{2,4})
And I created this .htaccess:
RewriteCond assets/img$1/.$2.$4/$3.$4 -s
RewriteRule ^assets/img(.*)/([a-zA-Z0-9-_\.]*)\.([^/]+)\.([a-z]{2,4})$ assets/img$1/.$2.$4/$3.$4 [NC,L,QSA]
RewriteRule ^assets/img(.*)/([a-zA-Z0-9-_\.]*)\.([^/]+)\.([a-z]{2,4})$ assets/img/image.php?path=$1&file=$2.$4&key=$3&ext=$4 [NC,L,QSA]
A request without the RewriteCond, where the rewritten location exists, is working normally. For those who’re interested, my complete .htaccess is posted here: http://pastie.org/1293667
The problem is that a
RewriteCondonly applies to the rule immediately following it, so your secondRewriteRuleis always run. One solution is to negate the test you are making, then have the next command skip the two commands you want to run.