37
40

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 5 years have passed since last update.

mod_rewrite よく使う条件

Last updated at Posted at 2014-08-18

メモ

ユーザーエージェントの制限

# Android (全体)
RewriteCond %{HTTP_USER_AGENT} ".*Android.*" [NC]

# Android (スマートフォン)
RewriteCond %{HTTP_USER_AGENT} ".*Android.*Mobile.*" [NC]

# iPhone
RewriteCond %{HTTP_USER_AGENT} ".*iPhone.*" [NC]

# iPad
RewriteCond %{HTTP_USER_AGENT} ".*iPad.*" [NC]

接続先の制限(ワイルドカード指定のドメインの場合)

RewriteCond %{HTTP_HOST} "^.*\.example\.com" [NC]

リダイレクト元の制限

RewriteCond %{HTTP_REFERER} "^.*\.example\.com" [NC]

接続元アドレス(ISP)の制限

RewriteCond %{REMOTE_ADDR} "^192\.168\..*" [NC]

接続元ドメイン(ISP)の制限

RewriteCond %{REMOTE_HOST} "^.*\.example\.com" [NC]

リモートユーザーの制限

# 2.2/2.4 での条件分岐が不要になる
RewriteCond %{REMOTE_USER} "^admin$" [NC]

リクエストメソッドの制限

RewriteCond %{REQUEST_METHOD} "^(GET|POST)$" [NC]

日付を指定する(営業日の指定)

# 以降 : 2014-04-01以降のみ
RewriteCond %{TIME_YEAR}%{TIME_MON}%{TIME_DAY} ">20140401"

# 以前 : 2014-04-01以前のみ
RewriteCond %{TIME_YEAR}%{TIME_MON}%{TIME_DAY} "<20140401"

# 同日 : 2014-04-01 と一致する。
RewriteCond %{TIME_YEAR}%{TIME_MON}%{TIME_DAY} "=20140401"

時刻を指定する(営業時間の指定)

# 以前 : 08時以前
RewriteCond %{TIME_HOUR}%{TIME_MIN} "<0800"

# 以降 : 18時以降
RewriteCond %{TIME_HOUR}%{TIME_MIN} ">1800"

曜日を指定する

# 日曜
RewriteCond %{TIME_WDAY} "0"

# 月曜
RewriteCond %{TIME_WDAY} "1"

# 火曜
RewriteCond %{TIME_WDAY} "2"

# 水曜
RewriteCond %{TIME_WDAY} "3"

# 木曜
RewriteCond %{TIME_WDAY} "4"

# 金曜
RewriteCond %{TIME_WDAY} "5"

# 土曜
RewriteCond %{TIME_WDAY} "6"

# 平日
RewriteCond %{TIME_WDAY} ">0"
RewriteCond %{TIME_WDAY} "<6"

# 週末
RewriteCond %{TIME_WDAY} "0" [OR]
RewriteCond %{TIME_WDAY} "6"
37
40
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
37
40

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?