【问题标题】:AH00124: Request exceeded the limit of 10 internal redirects on APACHE ServerAH00124:请求超出了 APACHE 服务器上 10 个内部重定向的限制
【发布时间】:2020-08-12 09:34:32
【问题描述】:

我在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

【问题讨论】:

  • LimitInternalRecursion 20 添加到httpd.conf 或.htaccess
  • 但是为什么会出现这个错误呢?有什么想法吗?
  • 我的解决方案有效吗?是因为重写规则的数量太多了。
  • 我尝试添加 LimitInternalRecursion 20,但结果是 500,请告诉我应该在哪里添加此规则,我已在文件末尾添加了它
  • 添加到 httpd.conf

标签: php apache .htaccess php-7


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2017-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-04
    • 2018-08-21
    • 2020-05-05
    • 1970-01-01
    • 2019-03-08
    相关资源
    最近更新 更多