 <p>The problem is that a <code>RewriteCond</code> only applies to the rule immediately following it, so your second <code>RewriteRule</code> is always run. One solution <a href="http://my.galagzee.com/2009/02/11/mod_rewrite-one-rewritecond-to-many-rewriterules/" rel="nofollow">is to negate the test you are making, then have the next command skip the two commands you want to run</a>.</p> <pre><code>RewriteCond %{DOCUMENT_ROOT}assets/img$1/.$2.$4/$3.$4 !-f RewriteRule . - [S=2] 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&amp;file=$2.$4&amp;key=$3 [NC,L,QSA] </code></pre>