You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apache服务器内部重定向超限及CPU占用100%问题求助

Fixing Apache Internal Redirect Loop & 100% CPU Usage

Hey there, let's break down how to resolve this frustrating redirect loop and sky-high CPU usage issue you're facing. Here's a step-by-step approach tailored to your scenario:

1. Fix Your .htaccess Redirect Condition

It looks like the RewriteCond %{ENV:REDIRECT_STATUS} ^... rule you added has incorrect syntax, which is why it's not stopping the loop. The correct way to prevent already-redirected requests from re-triggering your rules is to check if REDIRECT_STATUS is empty (meaning it's the initial request):

RewriteEngine On
# Only apply rules to the original, non-redirected request
RewriteCond %{ENV:REDIRECT_STATUS} ^$
# Add your actual RewriteRule(s) below this line
# Example: RewriteRule ^old-path$ /new-path [L,R=301]

The REDIRECT_STATUS environment variable is set to a non-empty value (like 200) after the first redirect, so this condition ensures your rules only run once per request, breaking the loop.

2. Enable Debug Logging to Find the Root Cause

The error log explicitly suggests using LogLevel debug to get a backtrace—this is critical for identifying exactly which rule or script is causing the loop. Here's how to set it up:

  1. Open your Apache configuration file (either httpd.conf, apache2.conf, or your virtual host file in sites-available/).
  2. Locate the LogLevel directive and change it to:
    LogLevel debug
    
  3. Restart Apache to apply the change:
    • For Debian/Ubuntu: sudo systemctl restart apache2
    • For CentOS/RHEL: sudo service httpd restart

Check your error logs again after reproducing the issue—you'll see a step-by-step trace of each internal redirect, which will show you exactly which rule or script is looping.

The referrer points to http://www.sarehah.ml/link.php?id=68783, so it's possible this PHP script is sending its own redirect headers that conflict with your .htaccess rules. For example:

  • The script might have a header("Location: ...") call that points to a URL which triggers your .htaccess redirects again.
  • It could be in a loop itself (e.g., checking a database value and redirecting indefinitely if the value is invalid).

Open link.php and review its redirect logic—look for any header() calls or conditional redirects that might be creating a loop with your Apache rules.

4. Address the 100% CPU Usage

The high CPU is a direct result of the redirect loop: Apache is stuck processing the same request over and over, spawning processes that never finish. Once you fix the loop, the CPU usage should drop back to normal automatically. If it doesn't, you'll need to check for other issues like slow database queries or poorly optimized PHP code, but resolving the loop is the priority here.

5. Temporary Band-Aid (Not a Long-Term Fix)

If you need to mitigate the issue immediately while troubleshooting, you can increase the LimitInternalRecursion value in your Apache configuration. This will allow more internal redirects before Apache stops the request, but it doesn't fix the root cause:

LimitInternalRecursion 20

Restart Apache after making this change, but make sure you still work through the earlier steps to eliminate the loop entirely.


内容的提问来源于stack exchange,提问作者Ziad Ahmed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 10:39:59