Aug 032007
 

mod_rewriteのRewriteCondディレクティブ。内部的にはRewriteRuleのあとに判定されます。
たとえばhttp接続してきたものをhttpsにリダイレクトするようなルールを書いたとします。

RewriteEngine on
RewriteLog logs/rewrite_log
RewriteLogLevel 4
RewriteCond %{HTTPS} off
RewriteRule . https://%{HTTP_HOST}/%{REQUEST_URI} [L]

サイトがwww.example.jpだったとして、http://www.example.jp/index.htmlにアクセスしてみると、RewriteLogには以下のようなログが出力されます。

(2) init rewrite engine with requested uri /index.html
(3) applying pattern '.' to uri '/index.html'
(4) RewriteCond: input='off' pattern='off' => matched
(2) rewrite /index.html -> https://www.example.jp/index.html
(2) explicitly forcing redirect with https://www.example.jp/index.html

2行目でRewriteRuleが判定され、3行目でRewriteCondが判定されていることになります。
先頭の()数字はRewriteLogLevelを表しているのでRewriteLogLevel 4にしたのですね。

で、こちらの処理順序ですが、こちらのメーリングリストで知りました。
RE: [users@httpd] RE: case insensitive rewrite rules and nested mapping
こちらのスレッドの最後のメールで

The order of processing is
rule-pattern –> condition(s) –> rule-substitution

と説明されていました。
ま、こんな内部的な順番知っててもしょうがないかもしれませんけど 😛

Sorry, the comment form is closed at this time.