DEBUG.WIKI
PanstarCloud:部署应用,接入 AI,云服务器与 AI 网关
晚安云;香港 CN2 ¥15/月
V.PS:让项目靠近用户,亚太、欧洲、北美 KVM VPS

解决 Apache 报错 AH00124 Request exceeded limit of 10

分析 Apache 在 .htaccess 或 RewriteRule 配置不当时报 AH00124 循环重定向的排查步骤,提供 RewriteCond 规则保护方案。

问题现象

访问 Apache 托管的网站时返回 500 内部错误,查看错误日志:

[core:error] [pid 1234] [client 192.168.1.10:54321] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel ref:debug' to get a backtrace.

触发根因

  1. .htaccess 或虚拟主机配置中的 RewriteRule 没有正确添加排除条件(RewriteCond),导致重定向后的目标 URL 再次命中同一规则,形成无限递归重写循环。
  2. 内部重定向超过了 Apache 默认的 10 次上限限制。

解决步骤与操作命令

步骤一:检查 .htaccess 中的重写规则

常见典型错误示范:

# 错误写法:将所有请求都重写为 index.php,包括 index.php 自身!
RewriteEngine On
RewriteRule ^(.*)$ index.php [L]

步骤二:增加非文件与非目录判断条件(标准健壮写法)

在执行路由回退之前,必须先排除真实存在的文件和目录,以及排除目标脚本本身:

RewriteEngine On
RewriteBase /

# 如果请求的是真实物理文件,则不重写
RewriteCond %{REQUEST_FILENAME} -f [OR]
# 如果请求的是真实物理目录,则不重写
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# 其余所有请求转发至 index.php
RewriteRule ^ index.php [L]

步骤三:验证配置语法并重载

sudo apachectl configtest
sudo systemctl reload apache2 # 或 systemctl reload httpd

验证确认

使用 curl 访问任意深层动态路径:

curl -I http://example.com/api/v1/users

返回 HTTP/1.1 200 OK,未再触发 AH00124 递归警告,路由正常分发至后端处理。