可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I'm trying to host a php based application with the following .htaccess values.
Options +FollowSymLinks Options -Indexes DirectoryIndex index.php RewriteEngine On RewriteBase /easydeposit RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [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.
回答1:
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
tags. mod_authz_core was introduced in Apache 2.3 and changed the way that access control is declared.
So, for example, instead of the 2.2 way of configuring
...
Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all
Order and Allow directives have been replaced with the Require directive:
Options Indexes FollowSymLinks AllowOverride All Require all granted
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
回答2:
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 Satisfy
directives. 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.
回答3:
This question/answer got me to the documentation for which I'm thankful, but the following was what solved it for me.
Previous .htaccess
file:
# 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
updated for 2.4 configuration
# 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 # Satisfy any Require ip 69.69.69 Require ip 71.71.71 Require all granted
回答4:
Are you sure that your are allowed to override Options in your .htaccess file? check main apache config file for this
回答5:
Options +FollowSymLinks Options -Indexes
on many shared hosting the above code often the main problems
回答6:
And you are absolutely sure that the apache user (probably _www) has access to the directory (/home/abc/opt/apache/htdocs/xyz/
)?
回答7:
Another example, rewrite from:
www.yoursite.com/script.php?product=123
to
www.yoursite.com/cat/product/123/
using
RewriteRule cat/(.*)/(.*)/$ /script.php?$1=$2
http://w3webtutorial.blogspot.com/2013/11/htaccess-and-modrewrite-in-your-php.html