首页 > 解决方案 > AH00124:请求超出了 APACHE 服务器上 10 个内部重定向的限制

问题描述

我在aws上使用php 7来运行我的php应用程序,它有一些不错的流量。但是在一天结束时,我会检查我的 apache 日志中的错误/活动。我每天发现一件常见的事情,有 10 到 15 行相同的错误

AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

但是我无法得到这个错误,为什么会发生,不知何故我知道它是由于重定向/.htaccess中的一些规则而发生的。我无法找到逻辑故障的位置,因为它在 localhost 上没有给出任何错误,也没有在运行任何脚本时出现错误。

下面是我的 .htaccess 代码

<IfModule mod_rewrite.c>
    RewriteEngine On

    # for subdomain like test.example.com to redirect to https://test.example.com
    #RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
    #RewriteCond %{HTTPS} off
    #RewriteCond %{HTTP_HOST} ^([\.\w\-]*)\.(com|in)$ [NC]
    #RewriteRule ^ https://%1.%2%{REQUEST_URI} [R=301,L,NE]

    # We are setting here the default file to load while the URL is called followed by fallback files
    DirectoryIndex index.php

    # Redirect all requests except only POST
    RewriteCond %{REQUEST_METHOD} !POST
    RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.(?:php?)[\s?/] [NC]
    RewriteRule ^ /%1%2 [R=302,L,NE]

    # Adds a trailing directory if rewritten URI is a direcory
    RewriteCond %{DOCUMENT_ROOT}/app/$1 -d
    RewriteRule ^(.*?[^/])$ %{REQUEST_URI}/ [L]

    # Over here we have set the default root directory now request will be directly made from this directory
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
    RewriteCond %{REQUEST_URI} !/app/ [NC]
    RewriteRule (.*) /app/$1 [L]

    # over here we're removing .php extensions
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.+?)/?$ $1.php [L]

    # code to make pretty URLS | we're using this code to achieve /category/slug
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^/?(.+)/([\w-]+)/([\d]+)$ app/post.php?&category=$2&page=$3 [L,QSA]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^/?(.+)/([\w-]+)/([\w-]+)$ app/post.php?&category=$2&slug=$3 [L,QSA]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^/?(.+)/([\d]+)$ app/index.php?page=$2 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^/?(.+)/([\w-]+)$ app/post.php?category=$2 [L]

    # we have set here custom error files to handle server errors
    ErrorDocument 404 /app/error_pages/404.php
    ErrorDocument 403 /app/error_pages/403.php
    ErrorDocument 500 /app/error_pages/500.php

    # We are setting here default charset & language headers setting for our website
    AddDefaultCharset UTF-8
    DefaultLanguage en-US

</IfModule>

# --------------------------------------------------- Caching Rules Section ---------------------------------------------------

<IfModule mod_headers.c>
    <filesMatch "\.(woff|otf|eot|opentype|ttf|woff2)$">
        #for a year
        Header set Cache-Control "max-age=31556952, public, must-revalidate"
    </filesMatch>
    <filesMatch "\.(ico|jpe?g|png|gif|swf)$">
        #for a month
        Header set Cache-Control "max-age=2629746, public, must-revalidate"
    </filesMatch>
    <filesMatch "\.(css|scss|min|min.css)$">
        #for a week
        Header set Cache-Control "max-age=604800, public, must-revalidate"
    </filesMatch>
    <filesMatch "\.(js|min|min.js)$">
        #for 3 days
        Header set Cache-Control "max-age=259200, private, must-revalidate"
    </filesMatch>
    #<filesMatch "\.(x?html?|xml)$">
    #   Header set Cache-Control "private, must-revalidate"
    #</filesMatch>
</IfModule>

# --------------------------------------------------- Caching Rules Section ---------------------------------------------------

Allow from all

# Disable directory browsing
Options All -Indexes

标签: phpapache.htaccessphp-7

解决方案


问题是您的重定向规则会导致无限循环。添加 LimitInternalRecursion 子句只会隐藏问题。

首先,您必须确定是什么请求导致了这个问题:检查您的 apache 访问日志行,返回代码为 500,其时间戳与错误日志中的时间戳相同。

其次,您可以激活重写规则日志记录以进行调试。请参阅:https ://httpd.apache.org/docs/2.4/mod/mod_rewrite.html


推荐阅读