1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Apache RewriteCondでRewrite Ruleに条件を付与する

Posted at

#はじめに

ApacheでRewriteruleを使用するときに、条件を付与するRewriteCondについての備忘録

RewriteCond

RewriteCond 変数名 条件(正規表現[フラグ] または 特定の構文(-fや-dなど))
RewriteRule URL書換&転送の記述

変数名に指定されたものが、条件にあっている場合、したのRewriteRuleを評価する

# RewriteCond %(REQUEST_FILENAME) !-f 

# RewriteRule rewrite-test/sub2/(.+) sub1/$1

この場合、リクエストに送られたファイルの名前が、存在しない場合、 sub2ではなくsub1というディレクトリの方で同様のファイルを探して開いて、という命令になる。

RewriteCondの変数名は、ネットで調べると一覧が結構出てくる。

また、正規表現の横につけるフラグには3種類あり、NC、OR、NVの三つがある。

正規表現ではなく、特定の構文で条件をつける場合は、
その特定の構文もネットで調べると一覧が載っているサイトがあったりする。
特定の構文の例は、-fや-bなど(-fは、ファイルが存在する、という意味)

まとめ

Apache全然まだまだ理解追いつかないので、書き殴ってる感じになってます。
自分以外が見ても、多分参考にならないかも、、、。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?