htaccessの設定


1. SSI

(1) 前提条件
SSIを使用するためには、「mod_include」が有効になっている必要があります。

(2) htaccessの記載方法
Options +Includes
Addtype text/html .shtml
AddOutputFilter INCLUDES .shtml

2. html拡張子でphpを利用する場合

<FilesMatch \.html$>
  AddHandler application/x-httpd-php
</FilesMatch>

3. アクセス制限

(1) ファイル拡張子
特定の拡張子のみアクセス拒否します。
【例1】「.log」ファイルをアクセス拒否。
<Files ~ "\.log$">
  Require all denied 
</Files>
※古い書き方の場合
<Files ~ "\.log$">
  Order deny,allow
  Deny from all 
</Files>
【例2】「.log」および「.dat」ファイルをアクセス拒否。
<Files ~ "\.(log|dat)$">
  Require all denied 
</Files>
※古い書き方の場合
<Files ~ "\.(log|dat)$">
  Order deny,allow
  Deny from all 
</Files>

(2) IPアドレス制限
[a] 特定のIPアドレスを許可
Require all denied
<RequireAny>
  Require ip ***.***.***.***
  Require ip ***.***.***.***/28
</RequireAny>
※古い書き方の場合
Order deny,allow
Deny from all
Allow from xxx.xxx.xxx.xxx
[b] 特定のIPアドレスを拒否
Require all granted
<RequireAny>
  Require not ip xxx.xxx.xxx.xxx
</RequireAny>
 
※古い書き方の場合
Order allow,deny
Allow from all
Deny from xxx.xxx.xxx.xxx

(3) Digest認証とIPアクセス制限を同時に掛ける場合
<RequireAll>
    AuthType Digest
    AuthName "This site is a protected site."
    AuthUserFile /var/_private/.htdigest
    Require valid-user
 
    <RequireAny>
       Require ip xxx.xxx.xxx.xxx
    </RequireAny>
</RequireAll>

(4) URLがドメイン名(FQDN)以外の場合はエラー
ドメイン名(FQDN)ではなく、IPアドレスやロードバランサーのDNS名などでアクセスしてきた場合は、403エラーとします。
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^xxx\.xxx\.xxx\.xxx [OR]
  RewriteCond %{HTTP_HOST} ^elb\.example\.jp [NC,OR]
  RewriteCond %{HTTP_HOST} ^ec2\.example\.jp [NC]
  RewriteRule ^.*$ - [F]
</IfModule>

4. アクセス許可

(1) 特定サイトからのiFrameのアクセスを許可
Header always set Content-Security-Policy: "frame-ancestors 'self' https://www.example.jp/;"

5. ダウンロード禁止

(1) Macシステムの作成する「.DS_Store」をダウンロード禁止
<Files ".DS_Store">
    Require all denied
</Files>



最終更新:2023年06月22日 07:10