You need to indicate that the image rewrite rule is the last in the line to prevent further rewriting. To do this, you simply indicate [L]
at the end of the rewrite rule.
RewriteEngine On RewriteRule /admin/images/(.*) /images/$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php
EDIT: Here is an explanation of why the problem occurs (taken from the comments section to provide clarification).
You see that the original %{REQUEST_FILENAME}
will never change no matter how many rewriting stages it takes. This means that when the second rule is reached, this variable will still point to the existing image (which is located in /admin/images/
), and not to the rewritten and non-existing one ( /images/
). This is the reason why the second rule always applies and why the two conditional lines from the example are almost always the first ones to be used for rewriting.
source share