The following is my directory structures:
admin\\
controls\\
images\\
media\\
lib\\
models\\
views\\
index.php
.htaccess
The following is m
Change the rule as follow:
RewriteEngine On
RewriteRule ^admin/images/(.*) images/$1
And put your .htaccess in your document root, or however in the '/admin' parent folder.
You need to specify that your image rewrite rule is the last one in the row in order to prevent further rewriting. For that you simply specify [L]
at the end of your image 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 why the problem occurs (taken from the comments section in order to provide clarification).
You see the original %{REQUEST_FILENAME}
will never change no matter how many stages of rewriting are performed. That means that when the second rule is reached that variable will actually still point to the existing image (which is in /admin/images/
) rather to the one being rewritten and non-existing (/images/
). That's the reason why the second rule will always be applied and why the two conditional lines from the example are almost always the first ones to be used during rewriting.