.htaccess 不适用于 Cent Os 6.4

Gau*_*ish 3 .htaccess httpd.conf centos6.4

我已经安装了 Cent Os 6.4 -Final Version 并为 PHP Web 开发设置了环境。

我的应用程序使用 .htaccess 进行 url 重写并拒绝直接访问文件。

我的 httpd 配置文件 - /etc/httpd/conf/httpd.conf 如下,

<Directory "/var/www/html">

#
# 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/2.2/mod/core.html#options
# for more information.
#
    Options Indexes FollowSymLinks

#
# 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

#
# Controls who can get stuff from this server.
#
    Order allow,deny
    Allow from all

</Directory>
Run Code Online (Sandbox Code Playgroud)

当我将AllowOverride None更改为AllowOverride All 时,它会要求进行身份验证。所以它对我不起作用并给出如下错误,

This server could not verify that you are authorized to access the document requested.
Run Code Online (Sandbox Code Playgroud)

要么您提供了错误的凭据(例如,错误的密码),要么您的浏览器不了解如何提供所需的凭据。

我的 .htaccess 看起来像,

deny from all
Run Code Online (Sandbox Code Playgroud)

HBr*_*ijn 5

使用AllowOverride Nonehttpd.conf 中的设置,.htaccess 文件将被完全忽略。所以你必须改变那个设置。

当 .htaccess 文件被允许时,apache 将检查从 DocumentRoot 向下的每个目录是否存在 .htaccess 文件,并将在那里应用设置,然后下降到下一个目录和那里的 .htaccess 文件。

例如./www/.htaccess,设置为“拒绝所有人”,尝试访问 /scripts/test/hello-world.php 的访问者将被拒绝,尽管 ./www/scripts/test/.htaccess可能已设置为“所有人都允许”。

因此,如果不是您的 PHP 脚本要求进行身份验证,您可能需要检查更高级别的目录以查找 .htaccess 文件。