0

次の書き換え条件があります

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)

Apache mod_rewriteマニュアルを読みましたが、上記の解釈に問題があります。

  1. RewriteCond %{REQUEST_FILENAME} !-f条件は、要求されたファイル名が欠落している場合を意味することを知っています

  2. この条件RewriteCond %{REQUEST_FILENAME} !-dは、要求されたディレクトリが欠落しているかどうかを意味します。

  3. RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)どういう意味かわかりません

私の理解では、条件が真であると評価された場合、条件を進めるルールが適用されますが、条件を進めるルールはRewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

ポイント3が何を指しているのかまだわからないので、ポイント1が真であると評価された場合、つまりリクエストファイルが欠落している場合、ポイント2、つまりリクエストディレクトリが欠落している場合、RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

編集

さらにかなり掘り下げてみると、ファイルまたはディレクトリではなく、それらが欠落しているわけではないことRewriteCond %{REQUEST_FILENAME} !-fを意味しているように見えます。RewriteCond %{REQUEST_FILENAME} !-d

4

2 に答える 2

1

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.

于 2013-01-07T20:29:34.810 に答える
1

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 :)

于 2013-01-07T20:29:56.017 に答える