[Apache][.htaccess]mod_rewrite で特定の IP に対してアクセス制限する方法

このエントリーをはてなブックマークに追加
はてなブックマーク - [Apache][.htaccess]mod_rewrite で特定の IP に対してアクセス制限する方法
Bookmark this on Yahoo Bookmark
Bookmark this on Livedoor Clip

mod_rewrite を使って特定の IP のみアクセスさせる、もしくはアクセスさせないようにするには以下のようにする。

アクセスを拒否

RewriteCond %{REMOTE_ADDR} ^192\.168\.0\.1$ [OR]
RewriteCond %{REMOTE_ADDR} ^192\.168\.0\.2$
RewriteCond %{REQUEST_URI} !^error\.html
RewriteRule .* error.html

アクセスを許可

RewriteCond %{REMOTE_ADDR} !^192\.168\.0\.1$
RewriteCond %{REMOTE_ADDR} !^192\.168\.0\.2$
RewriteCond %{REQUEST_URI} !^error\.html
RewriteRule .* error.html
Related Posts

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <img localsrc="" alt=""> <pre lang="" line="" escaped="" highlight="">