4

私はツールを開発していますが、この時点で立ち往生しています。各ディレクトリに一連のルールを定義したいのですが、基本的には「パブリック」フォルダーのみを使用可能にし、他のフォルダーへのアクセスを拒否したいと考えています。

私のディレクトリ構造は

uapi(root)/
    Application
    Config
    Public/
         Index.php
    Storage
    .htaccess

ここに.htaccessファイルがあります

<Directory /Public>
    Order Deny, Allow
    Allow from all
    <IfModule mod_rewrite.c>
        Options +FollowSymLinks
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ Index.php/$1 [L]
    </IfModule>
</Directory>

<Directory /Config>
    Order Deny, Allow
    Deny from all
</Directory>

<Directory /Application>
    Order Deny, Allow
    Deny from all
</Directory>

<Directory /Storage>
    Order Deny, Allow
    Deny from all
</Directory>
4

3 に答える 3

7

このドキュメントページにあるように、htaccess 内でディレクティブを使用することはできませんが、<Directory>サーバーの conf ファイル内でのみ使用できます。

とにかく、これは問題ではありません.htaccess。各ディレクトリ内に1つのファイルを保存できます。次のファイルを作成します。

パブリック/.htaccess

Order Deny, Allow
Allow from all
<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ Index.php/$1 [L]
</IfModule>

/Config/.htaccess

Order Deny, Allow
Deny from all

/アプリケーション/.htaccess

Order Deny, Allow
Deny from all

/ストレージ/.htaccess

Order Deny, Allow
Deny from all
于 2013-08-13T12:58:33.497 に答える
0

Apache httpd サーバー 2.4の場合、次の方法で実行できます。

httpd.conf または httpd/conf.d/ dir の .conf ファイル。

<Directory "/uapi/">
  Require all denied
</Directory>

<Directory "/uapi/public">
  Require all granted
</Directory>

この構成をテストしました。参照はこちらです。

Apache 構成ファイルにアクセスできない場合は、.htaccess ファイルでもこれを実行できるはずです。/uapi/.htaccess では次のようになります。

Require all denied

および /uapi/Public/.htaccess に

Require all granted

前述のように、.htaccess ファイル内では使用できません。Apache ドキュメントから:

Note that unlike <Directory> and <Location> sections, <Files> sections can be used inside .htaccess files.

より一般的なドキュメント: https://httpd.apache.org/docs/2.4/howto/access.html

于 2020-07-24T22:06:49.657 に答える