Reputation: 7105
I have the following rewrite conditions
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
I have read the Apache mod_rewrite manual however am having difficulty interpreting the above.
I know that the condition RewriteCond %{REQUEST_FILENAME} !-f
means if the requested file name is missing
The condition RewriteCond %{REQUEST_FILENAME} !-d
means if the requested directory is missing.
I have no idea what RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
means
My understanding is rules proceeding conditions are applied if the conditions are evaluated true but the rule I have proceeding the conditions is RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
As I don't know what Point 3 refers to yet, would I be correct to interpret that if Point 1 evaluates to be true i.e. if the request file is missing AND Point 2 i.e. if the request directory is missing then do RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
EDIT
Having dug around a fair bit further it appears that RewriteCond %{REQUEST_FILENAME} !-f
and RewriteCond %{REQUEST_FILENAME} !-d
mean when anything that is not a file or directory AND not that they are missing.
Upvotes: 0
Views: 141
Reputation: 5490
The last line is saying "the requested URI doesn't end with one of the listed suffixes." (Strictly speaking, as KingCrunch pointed out, it checks whether one of the suffixes is in the string at all, whether at the end or in the middle.)
Rules following conditions are applied if the conditions are true; rules preceding the conditions are separate and have no connection to the conditions.
You are correct in that if condition 1 and condition 2 and condition 3 all evaluate to true, then the rule following will be executed.
To break down that last regular expression:
The !
means not, i.e., if REQUEST_URI does not match the expression;
.*
means any characters zero or more times;
\.
means a period (or full-stop) -- this is escaped with a backslash because otherwise .
means any character;
(ico|gif|jpg|jpeg|png|js|css)
means one of the strings separated by the vertical bar |
, that is, "ico
or gif
or jpg
etc."
If the regular expression had been written ending with $
(the end-of-string marker) then there could be no characters after the suffix; as written now, any characters may follow.
So the RewriteCond is checking if REQUEST_URI does not match some characters, followed by a period, followed by one of the file type suffixes listed. If it does not, then the condition evaluates to true.
Upvotes: 1
Reputation: 132071
The last condition means "When REQUEST_URI
does not contain [1] one of 'ico', 'gif', 'jpg' (and so on)". When all three rules evaluates to true
, the (not shown) RewriteRule
is applied.
[1] Which is kind of ... incomplete, because it should say "not end in", but it doesn't. But this is a different point :)
Upvotes: 1