|
htaccessサンプル/アクセス制限(IPアドレス、ホスト名)
実際に動作するアクセス制限(IPアドレス、ホスト名)のサンプルを掲載しています。 サンプルをご確認のうえ、htaccessファイル作成してください。 当サイトでは、htaccessの作成機能もありますので、是非ご利用ください。
1.携帯電話(3キャリア)IPアドレスからのアクセスを拒否
- 同ディレクトリに配置されている「.htaccess」により、携帯3キャリア(docomo,au,softbank)からアクセスは拒否されます。
- 携帯電話のIPアドレスは、2010年11月に掲載されている情報を利用しています。
|
(1)「.htaccess」ファイルの内容(☆1)
<Files ~ "^\.ht">
deny from all
</Files>
ErrorDocument 403 /sample/access_ip/mb_error.html
order allow,deny
allow from all
#docomo
deny from 210.153.84.0/24
deny from 210.136.161.0/24
deny from 210.153.86.0/24
deny from 124.146.174.0/24
deny from 124.146.175.0/24
deny from 202.229.176.0/24
deny from 202.229.177.0/24
deny from 202.229.178.0/24
deny from 202.229.179.0/24
deny from 111.89.188.0/24
deny from 111.89.189.0/24
deny from 111.89.190.0/24
deny from 111.89.191.0/24
deny from 210.153.87.0/24
#au
deny from 210.230.128.224/28
deny from 121.111.227.160/27
deny from 61.117.1.0/28
deny from 219.108.158.0/27
deny from 219.125.146.0/28
deny from 61.117.2.32/29
deny from 61.117.2.40/29
deny from 219.108.158.40/29
deny from 219.125.148.0/25
deny from 222.5.63.0/25
deny from 222.5.63.128/25
deny from 222.5.62.128/25
deny from 59.135.38.128/25
deny from 219.108.157.0/25
deny from 219.125.145.0/25
deny from 121.111.231.0/25
deny from 121.111.227.0/25
deny from 118.152.214.192/26
deny from 118.159.131.0/25
deny from 118.159.133.0/25
deny from 118.159.132.160/27
deny from 111.86.142.0/26
deny from 111.86.141.64/26
deny from 111.86.141.128/26
deny from 111.86.141.192/26
deny from 118.159.133.192/26
deny from 111.86.143.192/27
deny from 111.86.143.224/27
deny from 111.86.147.0/27
deny from 111.86.142.128/26
deny from 111.86.142.192/26
deny from 111.86.143.0/26
#softbank
deny from 123.108.237.0/27
deny from 202.253.96.224/27
deny from 210.146.7.192/26
deny from 210.175.1.128/25
deny from 123.108.237.224/27
deny from 202.253.96.0/27
(2)サーバーのディレクトリ構成
| (1階層目) |
(2階層目) |
(3階層目) |
(4階層目) |
| /public_html |
/sample |
/access_ip |
/pc_only |
└.htaccess (共通htaccess) |
└access_ip.html (当ページ) |
└mb_error.html |
└.htaccess (前記☆1) |
| └index.html |
2.携帯電話(3キャリア)IPアドレスからのアクセスのみ許可
 |
携帯電話からのアクセスはこちらをご利用ください。 上記リンク先と同じURLに接続されます。 |
| (cmanで作成しました) |
- サンプルは、「/sample/access_ip/mb_only/」ディレクトリにリンクされています。
- 同ディレクトリに配置されている「.htaccess」により、携帯3キャリア(docomo,au,softbank)からのアクセスのみ許可され、PCなどからのアクセスは拒否されます。
- 携帯電話のIPアドレスは、2010年11月に掲載されている情報を利用しています。
|
(1)「.htaccess」ファイルの内容(☆2)
<Files ~ "^\.ht">
deny from all
</Files>
ErrorDocument 403 /sample/access_ip/pc_error.html
order deny,allow
deny from all
#docomo
allow from 210.153.84.0/24
allow from 210.136.161.0/24
allow from 210.153.86.0/24
allow from 124.146.174.0/24
allow from 124.146.175.0/24
allow from 202.229.176.0/24
allow from 202.229.177.0/24
allow from 202.229.178.0/24
allow from 202.229.179.0/24
allow from 111.89.188.0/24
allow from 111.89.189.0/24
allow from 111.89.190.0/24
allow from 111.89.191.0/24
allow from 210.153.87.0/24
#au
allow from 210.230.128.224/28
allow from 121.111.227.160/27
allow from 61.117.1.0/28
allow from 219.108.158.0/27
allow from 219.125.146.0/28
allow from 61.117.2.32/29
allow from 61.117.2.40/29
allow from 219.108.158.40/29
allow from 219.125.148.0/25
allow from 222.5.63.0/25
allow from 222.5.63.128/25
allow from 222.5.62.128/25
allow from 59.135.38.128/25
allow from 219.108.157.0/25
allow from 219.125.145.0/25
allow from 121.111.231.0/25
allow from 121.111.227.0/25
allow from 118.152.214.192/26
allow from 118.159.131.0/25
allow from 118.159.133.0/25
allow from 118.159.132.160/27
allow from 111.86.142.0/26
allow from 111.86.141.64/26
allow from 111.86.141.128/26
allow from 111.86.141.192/26
allow from 118.159.133.192/26
allow from 111.86.143.192/27
allow from 111.86.143.224/27
allow from 111.86.147.0/27
allow from 111.86.142.128/26
allow from 111.86.142.192/26
allow from 111.86.143.0/26
#softbank
allow from 123.108.237.0/27
allow from 202.253.96.224/27
allow from 210.146.7.192/26
allow from 210.175.1.128/25
allow from 123.108.237.224/27
allow from 202.253.96.0/27
(2)サーバーのディレクトリ構成
| (1階層目) |
(2階層目) |
(3階層目) |
(4階層目) |
| /public_html |
/sample |
/access_ip |
/pc_only |
└.htaccess (共通htaccess) |
└access_ip.html (当ページ) |
└pc_error.html |
└.htaccess (前記☆2) |
| └index.html |
サンプルの動作環境
以下の環境でサンプル作成と動作確認を行っています。
| WEBサーバー |
Apache/2.2.3 |
| 動作確認OS |
Windows (XP以降) |
使用環境によってはサンプルが動作しない場合や、サンプル通りにhtaccessファイルを作成しても動作が異なる場合があります。 |