【问题标题】:Error with .htaccess and mod_rewrite.htaccess 和 mod_rewrite 出错
【发布时间】:2012-08-21 20:34:19
【问题描述】:

我正在尝试使用以下 .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

我不确定为什么会这样。任何帮助表示赞赏。

【问题讨论】:

    标签: php .htaccess mod-rewrite


    【解决方案1】:

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

    所以,例如,代替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

    【讨论】:

    • 真的没有办法在不侵入Apache的配置文件的情况下处理它吗?问题是你必须有root权限才能做到这一点......
    【解决方案2】:

    这个问题/答案让我找到了documentation,对此我很感激,以下是为我解决的问题。

    以前的.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
    

    此配置产生如下错误:

    [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 .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
    

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        【解决方案4】:

        您确定允许覆盖 .htaccess 文件中的选项吗?检查主 apache 配置文件

        【讨论】:

        • 我在我的 httpd.conf 文件中启用了覆盖选项。
        【解决方案5】:
        Options +FollowSymLinks
        Options -Indexes
        

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

        【讨论】:

        • 我也试过没有上面的代码,但似乎没有任何区别......
        【解决方案6】:

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

        【讨论】:

        • 绝对是的。我确保更改目录的用户/组权限
        【解决方案7】:

        另一个例子,改写自:

        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

        【讨论】:

          【解决方案8】:

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

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

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

          【讨论】:

            猜你喜欢
            • 2014-09-25
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-01-19
            • 2011-01-12
            • 2014-05-18
            • 1970-01-01
            相关资源
            最近更新 更多