.htaccess 和 mod_rewrite 错误

2022-08-30 19:33:22

我正在尝试托管一个基于php的应用程序,其中包含以下.htaccess值。

Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php

RewriteEngine On
RewriteBase /easydeposit
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

但是,我一直面临以下两个错误,

[access_compat:error] [pid 25330:tid 27] AH01797: client denied by server configuration: /home/abc/opt/apache/htdocs/xyz/system/
[access_compat:error] [pid 25330:tid 27]  AH01797: client denied by server configuration: /home/abc/opt/apache/htdocs/xyz/private/
[access_compat:error] [pid 25330:tid 27] AH01797: client denied by server configuration: /home/abc/opt/apache/htdocs/xyz/application/
[authz_core:error] [pid 25330:tid 27]  AH01630: client denied by server configuration: /home/abc/opt/apache/htdocs/xyz/.htaccess

我不知道为什么会发生这种情况。任何帮助是值得赞赏的。


答案 1

如果您最近升级到高于版本 2.2 的 Apache 版本,则authz_core错误错误可能来自标记中的 httpd.conf 或 httpd-vhosts.conf 文件。mod_authz_core是在Apache 2.3中引入的,并改变了访问控制的声明方式。<Document>

因此,例如,而不是2.2的配置方式...<Directory>

    <Directory "C:/wamp">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

OrderAllow 指令已替换为 Require 指令:

    <Directory "C:/wamp">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

来源 http://www.andrejfarkas.com/2012/06/fun-with-wamp-server-and-apache-2-4-2/ http://httpd.apache.org/docs/2.4/upgrading.html


答案 2

这个问题/答案让我找到了我感激的文档,以下是为我解决它的原因。

一个 .htaccess 文件:

# password protection allowing multiple resources
AuthType Basic
AuthName "Restricted Area"
AuthUserFile C:\path\to\.htpasswd
AuthGroupFile /dev/null
Require valid-user

# allow public access to the following resources
SetEnvIf Request_URI "(path/to/public_files/.*)$" allow

# these lines must be updated

Order allow,deny
# Allowing an ip range:
Allow from 69.69.69
# Allowing another range:
Allow from 71.71.71

Satisfy any

此配置产生错误,例如:

[星期四 12月 08 10:29:20.347782 2016][access_compat:错误][pid 2244:tid 15876][客户端 93.93.93.93:49340]AH01797:服务器配置拒绝客户端:C:/path/to/index.php

针对 2.4 配置进行了更新

# 7 lines unchanged...shown again for clarification 
AuthType Basic
AuthName "Restricted Area"
AuthUserFile C:\path\to\.htpasswd
AuthGroupFile /dev/null
Require valid-user
SetEnvIf Request_URI "(path/to/public_files/.*)$" allow

# these are the changes replacing:

# Order allow,deny
# Allow from <range>
# Satisfy any

Require ip 69.69.69
Require ip 71.71.71
Require all granted

推荐