.htaccessはまだファイルへのアクセスを許可しています

Jul 03 2020

ランダムなユーザーがURLを使用してWebファイルを参照するのを防ぎたい場合は、.htaccessファイルを使用する必要があります。

以下にコードを追加しました。.htaccessファイルを作成し、それをincludeフォルダー内に配置して、ユーザーがdatabase.phpファイルに移動して読み取れないようにしました。

ここにある指示に従ってください: https://www.plothost.com/kb/how-to-deny-access-to-a-specific-file-on-your-site-via-htaccess/

もちろん、少し変更を加えました。

これが私の.htaccessファイルのコードです:

<files database.php>
Order Allow,Deny
Deny from all
</files>

上記を使用して、database.phpファイルに直接URLを送信することができます。これを防ぐ必要があります。

私は何が間違っているのですか?

回答

2 F.Müller Jul 03 2020 at 02:12

以下を確認してください。

  1. .htaccessファイルが実際には「.htaccess」と呼ばれていることを確認してください
  2. .htaccessファイルは正しいディレクトリにある か、ファイルのパスが.htaccessファイルからの相対パスである必要があります。

これを自分のマシンで実行しました。使用したのと同じコード。私の構造:

ファイルは同一です。ルートディレクトリの.htaccessファイルの内容をコメントアウトしました。だから今私は呼び出すことができますlocalhost:8080/database.phpが、localhost:8080/test/database.php=>私はError 403(アクセスが拒否されました)を取得します。

編集

このガイドはどうですか?htaccessを設定する

合法的に見えます。これは私の設定です。ガイドによると、それはちょうどこの設定ファイルを設定して再起動することです。

編集2

私が開いたhttpd.confが正しいものではないことがわかりました。私は以下の下で正しいものを見つけました:Application/XAMPP/xamppfiles/etc/httpd.conf.

このファイルでは、以下を検索する必要があります。

# 
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
<Directory "/Applications/XAMPP/xamppfiles/htdocs">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/trunk/mod/core.html#options
    # for more information.
    #
    #Options Indexes FollowSymLinks
    # XAMPP
    Options Indexes FollowSymLinks ExecCGI Includes

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    #AllowOverride None
    # since XAMPP 1.4:
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

ここであなたはこれを見つけます:

#AllowOverride None  # this does deactivate .htaccess
# since XAMPP 1.4:
AllowOverride All    # this does activate .htaccess

少なくとも私にとっては、これが.htaccessの書き換えに単独で責任を負っていました。AllowOverride Noneに設定すると、.htaccessは完全に無視されます。

1 anubhava Jul 03 2020 at 02:21

これmod_rewriteは、サイトルート.htaccessのルールを使用して行うことができます。

RewriteEngine On

RewriteCond %{THE_REQUEST} /database\.php[?\s/] [NC]
RewriteRule ^ - [F]