かきスタンプ

福岡でフリーランスの物流系のエンジニアやってます。

Apache:mod_rewrite モジュールの、『RewriteCond %{HTTPS} off』がよく分からなかったから調べた。

.htaccess の記述設定で

RewriteCond %{HTTPS} off
RewriteCond %{HTTPS} !on

といった記述があった。

が、RewriteCond の構文は、

RewriteCond TestString CondPattern(正規表現) [flags]

となっている。 https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond

え? 「off」って正規表現じゃなくね? って思ってマニュアルをよく調べたら、こんな記述があった。

If the TestString has the special value expr, the CondPattern will be treated as an ap_expr. HTTP headers referenced in the expression will be added to the Vary header if the novary flag is not given.
 
(TestStringが特別な値だったら、CondPattern は、正規表現でなく ap_exprとして扱われます。 )

って事だった。

という訳で、参照するべきページはここ。 https://httpd.apache.org/docs/current/expr.html

HTTPS  -  "on" if the request uses https, "off" otherwise
(リクエストがhttpsを使用している場合は 'on'、それ以外の場合は 'off')

って事らしい。

なので、常時SSL対応として .htaccess(または httpd.conf)を編集する場合、

RewriteCond %{HTTPS} off

を決まり文句として考えて良さそう。