Php .htaccess仍允许访问文件
如果我想阻止随机用户使用URL浏览web文件,我需要使用.htaccess文件 我在下面添加了我的代码。我已经创建了一个.htaccess文件,并将其放在include文件夹中,以防止用户浏览和读取我的database.php文件 按照此处的说明进行操作: 当然,我做了一些小改动 以下是我的.htaccess文件中的代码:Php .htaccess仍允许访问文件,php,.htaccess,server,Php,.htaccess,Server,如果我想阻止随机用户使用URL浏览web文件,我需要使用.htaccess文件 我在下面添加了我的代码。我已经创建了一个.htaccess文件,并将其放在include文件夹中,以防止用户浏览和读取我的database.php文件 按照此处的说明进行操作: 当然,我做了一些小改动 以下是我的.htaccess文件中的代码: <files database.php> Order Allow,Deny Deny from all </files> 使用上面的方法,我仍然能够
<files database.php>
Order Allow,Deny
Deny from all
</files>
使用上面的方法,我仍然能够将URL直接链接到database.php文件。我需要防止这种情况发生
我做错了什么?请检查以下内容: 请确保.htaccess文件的名称为.htaccess .htaccess文件必须位于正确的目录中,或者该文件的路径必须相对于.htaccess文件。 我只是在我的机器上运行了这个。与您使用的代码相同。 我的结构: 这些文件是相同的。我在根目录中注释掉了.htaccess文件中的内容。所以现在我可以调用localhost:8080/database.php,但不能调用localhost:8080/test/database.php=>我得到一个错误403拒绝访问 编辑 这本指南怎么样? 看起来合法。这是我的配置。根据指南,它只是关于设置这个配置文件并重新启动 编辑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>
至少对我来说,这是重写.htaccess的唯一原因。当我将其设置为AllowOverride None时,.htaccess被完全忽略。请检查以下内容: 请确保.htaccess文件的名称为.htaccess .htaccess文件必须位于正确的目录中,或者该文件的路径必须相对于.htaccess文件。 我只是在我的机器上运行了这个。与您使用的代码相同。 我的结构: 这些文件是相同的。我在根目录中注释掉了.htaccess文件中的内容。所以现在我可以调用localhost:8080/database.php,但不能调用localhost:8080/test/database.php=>我得到一个错误403拒绝访问 编辑 这本指南怎么样? 看起来合法。这是我的配置。根据指南,它只是关于设置这个配置文件并重新启动 编辑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>
至少对我来说,这是重写.htaccess的唯一原因。当我将其设置为AllowOverride None时,.htaccess被完全忽略。您可以使用site root.htaccess中的mod_重写规则来执行此操作:
RewriteEngine On
RewriteCond %{THE_REQUEST} /database\.php[?\s/] [NC]
RewriteRule ^ - [F]
您可以使用site root.htaccess中的mod_重写规则执行此操作:
RewriteEngine On
RewriteCond %{THE_REQUEST} /database\.php[?\s/] [NC]
RewriteRule ^ - [F]
检查this@aviboy2006-我尝试了那一页上的前两个答案。我仍然可以使用第一个答案将URL链接到文件夹。第二个,虽然看起来确实有效,但当返回index.php时,数据库似乎已断开连接。@JohnBeasley请告诉我我的解决方案是否适用于您。检查this@aviboy2006-我尝试了那一页上的前两个答案。我仍然可以使用第一个答案将URL链接到文件夹。第二个解决方案虽然似乎有效,但返回index.php时,数据库似乎已断开连接。@JohnBeasley请告诉我我的解决方案是否适用于您。我的include文件夹中有.htaccess文件。我的include文件夹中仅有的两个文件是database.php和.htaccess,上面列出了我的代码,但我仍然能够将URL链接到该文件。想法?@JohnBeasley尝试将.htaccess移动到您的根目录,我将使用include文件夹检查部件。。。等等。我把文件移到了根目录下,但还是没有成功。试着在.htaccess中添加顺序Allow、Deny、newline Deny和all。只要删除files标记,看看会发生什么。@JohnBeasley哈哈。别担心。至少您已经发现.htaccess必须在apache配置中启用。这就是您的解决方案不起作用的原因。我以为你用的是xampp点灯?我只是在windows和iOS上这样做,我从来没有真正配置过任何东西。顺便说一句,你的设置是什么?我的include文件夹中有.htaccess文件。我的include文件夹中仅有的两个文件是database.php和.htaccess,上面列出了我的代码,但我仍然能够将URL链接到该文件。想法?@JohnBeasley尝试将.htaccess移动到您的根目录,我将使用include文件夹检查部件。。。等等。我把文件移到了根目录下,但还是没有成功。试着在.htaccess中添加顺序Allow、Deny、newline Deny和all。只要删除files标记,看看会发生什么。@JohnBeasley哈哈。别担心。至少您已经发现.htaccess必须在apache配置中启用。这就是您的解决方案不起作用的原因。我以为你用的是xampp点灯?我只是在电视上做的
windows和iOS以及我从未真正需要配置任何东西。顺便说一句,你的设置是什么?你应该注释掉你的完全仍然没有运气。我仍然可以直接使用URL访问该文件。想法?很有趣。。。我没有收到任何错误。我猜这意味着。htaccess没有启用?它因操作系统和Apache安装而异。请在谷歌上搜索,谢谢你的帮助。你应该评论一下你的完全还是没有运气。我仍然可以直接使用URL访问该文件。想法?很有趣。。。我没有收到任何错误。我猜这意味着。htaccess没有启用?它因操作系统和Apache安装而异。请通过谷歌搜索谢谢你的帮助。