Error with .htaccess and mod_rewrite



我正试图用以下.htaccess值托管一个基于php的应用程序。

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

我不知道为什么会发生这种事。感谢您的帮助。

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

因此,例如,与配置<Directory>的2.2方式不同。。。

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

订单允许指令已替换为要求指示:

    <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

这个问题/答案让我找到了我很感激的文档,下面是我解决问题的方法。

上一个.htaccess文件:

# password protection allowing multiple resources
AuthType Basic
AuthName "Restricted Area"
AuthUserFile C:pathto.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

此配置会产生以下错误:

【2016年12月8日星期四10:29:20.347782】【access_compat:error】【pid 2244:tid 15876】【client 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:pathto.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

我怀疑这与您的htaccess文件有任何关系。错误由mod_access_compat引发,它提供AllowDenyOrderSatisfy指令。在某个地方,您的允许和拒绝可能配置错误。至于最后的.htaccess错误,它来自mod_authz_core,所以可能有一些上游的东西直接阻止了对.htacccess文件的访问。

您确定允许重写.htaccess文件中的Options吗?检查这个的主apache配置文件

Options +FollowSymLinks
Options -Indexes

在许多共享主机上,上面的代码经常是的主要问题

您绝对确定apache用户(可能是_www)有权访问目录(/home/abc/opt/apache/htdocs/xyz/)吗?

另一个例子,重写自:

www.yoursite.com/script.php?product=123 

www.yoursite.com/cat/product/123/

使用

RewriteRule cat/(.*)/(.*)/$ /script.php?$1=$2

http://w3webtutorial.blogspot.com/2013/11/htaccess-and-modrewrite-in-your-php.html

对我来说,wp-config文件夹中有一个.htaccess文件,其中包含以下条目

Order deny,allow
Deny from all
<Files ~ ".(xml|css|jpe?g|png|gif|js)$">
Allow from all
</Files>

这导致界面中的图标显示为正方形。

最新更新