php .htaccess 和 mod_rewrite 出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12140559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error with .htaccess and mod_rewrite
提问by pratz
I'm trying to host a php based application with the following .htaccess values.
我正在尝试使用以下 .htaccess 值托管基于 php 的应用程序。
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine On
RewriteBase /easydeposit
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L]
However, I keep facing the following two errors,
但是,我一直面临以下两个错误,
[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
I'm not sure why this is happening. Any help is appreciated.
我不确定为什么会这样。任何帮助表示赞赏。
回答by Mabbage
If you have recently upgraded to a version of Apache greater than version 2.2, the authz_core error error might be coming from your httpd.conf or httpd-vhosts.conf file in the <Document>tags. mod_authz_core was introduced in Apache 2.3 and changed the way that access control is declared.
如果您最近升级到高于 2.2 版的 Apache,则 authz_core 错误可能来自<Document>标签中的 httpd.conf 或 httpd-vhosts.conf 文件。mod_authz_core 是在 Apache 2.3 中引入的,它改变了声明访问控制的方式。
So, for example, instead of the 2.2 way of configuring <Directory>...
因此,例如,而不是 2.2 配置方式<Directory>...
<Directory "C:/wamp">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Orderand Allowdirectives have been replaced with the Requiredirective:
Order和Allow指令已替换为Require指令:
<Directory "C:/wamp">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Sources http://www.andrejfarkas.com/2012/06/fun-with-wamp-server-and-apache-2-4-2/http://httpd.apache.org/docs/2.4/upgrading.html
来源 http://www.andrejfarkas.com/2012/06/fun-with-wamp-server-and-apache-2-4-2/ http://httpd.apache.org/docs/2.4/upgrading.html
回答by WEBjuju
This question/answer got me to the documentationfor which I'm thankful, and the following was what solved it for me.
这个问题/答案让我找到了我很感激的文档,以下是为我解决的问题。
Previous .htaccessfile:
上一个.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
This configuration was producing errors like:
此配置产生如下错误:
[Thu Dec 08 10:29:20.347782 2016] [access_compat:error] [pid 2244:tid 15876] [client 93.93.93.93:49340] AH01797: client denied by server configuration: C:/path/to/index.php
[Thu Dec 08 10:29:20.347782 2016] [access_compat:error] [pid 2244:tid 15876] [client 93.93.93.93:49340] AH01797:客户端被服务器配置拒绝:C:/path/to/index
updated for 2.4 configuration
更新了 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
回答by Jon Lin
I doubt this has anything to do with your htaccess file. The errors are thrown by mod_access_compat, which provides the Allow, Deny, Order, and Satisfydirectives. Somewhere, you probably have your allow's and deny's configured wrong. As for the .htaccess error at the end, it's from mod_authz_core, so there may be something upstream that blocks access to .htaccess files outright.
我怀疑这与您的 htaccess 文件有关。这些错误被抛出mod_access_compat,它提供了Allow,Deny,Order,和Satisfy指令。在某个地方,您可能将允许和拒绝配置错误。至于最后的 .htaccess 错误,它来自mod_authz_core,因此上游可能会完全阻止对 .htaccess 文件的访问。
回答by Asher Black
For me, there was an .htaccess file in the wp-config folder that had these entries
对我来说,wp-config 文件夹中有一个 .htaccess 文件,其中包含这些条目
Order deny,allow
Deny from all
<Files ~ ".(xml|css|jpe?g|png|gif|js)$">
Allow from all
</Files>
That caused icons in the interface to show up as squares.
这导致界面中的图标显示为正方形。
回答by Bijon Krishna Bairagi
Another example, rewrite from:
另一个例子,重写自:
www.yoursite.com/script.php?product=123
to
到
www.yoursite.com/cat/product/123/
using
使用
RewriteRule cat/(.*)/(.*)/$ /script.php?=
http://w3webtutorial.blogspot.com/2013/11/htaccess-and-modrewrite-in-your-php.html
http://w3webtutorial.blogspot.com/2013/11/htaccess-and-modrewrite-in-your-php.html
回答by Sadeq
Are you sure that your are allowed to override Options in your .htaccess file? check main apache config file for this
您确定允许您覆盖 .htaccess 文件中的选项吗?为此检查主 apache 配置文件
回答by cepeko
Options +FollowSymLinks
Options -Indexes
on many shared hosting the above code often the main problems
在许多共享主机上,上述代码往往是主要问题
回答by LasseValentini
And you are absolutely sure that the apache user (probably _www) has access to the directory (/home/abc/opt/apache/htdocs/xyz/)?
并且您绝对确定 apache 用户(可能是 _www)有权访问目录 ( /home/abc/opt/apache/htdocs/xyz/)?

