2 回答
TA贡献1772条经验 获得超8个赞
请检查以下内容:
确保您的 .htaccess 文件确实名为“.htaccess”
.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 被完全忽略。
TA贡献1875条经验 获得超3个赞
您可以使用mod_rewrite站点根 .htaccess 中的规则来执行此操作:
RewriteEngine On
RewriteCond %{THE_REQUEST} /database\.php[?\s/] [NC]
RewriteRule ^ - [F]
- 2 回答
- 0 关注
- 169 浏览
添加回答
举报