为了账号安全,请及时绑定邮箱和手机立即绑定

.htaccess 仍然允许访问文件

.htaccess 仍然允许访问文件

PHP
江户川乱折腾 2023-07-08 20:13:52
如果我想阻止随机用户使用 URL 浏览 Web 文件,我需要使用 .htaccess 文件。我在下面添加了我的代码。我创建了一个 .htaccess 文件并将其放置在我的 include 文件夹中,以防止用户导航到并读取我的 database.php 文件。当然我做了一些细微的修改。这是我的 .htaccess 文件中的代码:<files database.php> Order Allow,Deny Deny from all </files>使用上面的内容,我仍然能够直接访问 database.php 文件。我需要阻止这种情况发生。我究竟做错了什么?
查看完整描述

2 回答

?
料青山看我应如是

TA贡献1772条经验 获得超7个赞

请检查以下内容:

  1. 确保您的 .htaccess 文件确实名为“.htaccess”

  2. .htaccess 文件必须位于正确的目录中,或者文件的路径必须相对于 .htaccess 文件。

我刚刚在我的机器上运行了这个。您使用过的相同代码。我的结构:

//img2.sycdn.imooc.com/64a95321000125b402670109.jpg

这些文件是相同的。我注释掉了根目录中的 .htaccess 文件中的内容。所以现在我可以打电话localhost:8080/database.php,但不能localhost:8080/test/database.php=>我收到Error 403(访问被拒绝)。

编辑

这里的指南怎么样? 设置 htaccess

看起来合法。这是我的配置。根据指南,这只是设置此配置文件并重新启动。

//img1.sycdn.imooc.com/64a9532f0001973406470156.jpg

编辑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 被完全忽略。


查看完整回答
反对 回复 2023-07-08
?
翻过高山走不出你

TA贡献1875条经验 获得超3个赞

您可以使用mod_rewrite站点根 .htaccess 中的规则来执行此操作:


RewriteEngine On


RewriteCond %{THE_REQUEST} /database\.php[?\s/] [NC]

RewriteRule ^ - [F]


查看完整回答
反对 回复 2023-07-08
  • 2 回答
  • 0 关注
  • 130 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信