CRITICAL

Solved: Apache Infinite Redirect Loop Error (AH00124) in Apache 2.4.62+

Quick Fix Summary

TL;DR

Immediately disable or simplify your .htaccess rewrite rules and restart Apache to break the loop.

Apache's internal redirect limit prevents infinite loops from consuming server resources. This error occurs when rewrite rules or aliases create a circular path that never resolves to a final resource.

Diagnosis & Causes

  • Circular RewriteRule conditions in .htaccess.
  • Conflicting Alias and Redirect directives.
  • Incorrect use of the [L] (last) flag in mod_rewrite.
  • Overlapping Directory and Location directives.
  • ProxyPass and RewriteRule interactions creating loops.
  • Recovery Steps

    1

    Step 1: Isolate and Disable the Problematic Configuration

    Quickly stop the loop by disabling the most likely culprit, typically .htaccess rewrite rules, to restore service.

    bash
    # Rename .htaccess to disable it
    sudo mv /var/www/html/.htaccess /var/www/html/.htaccess.disabled
    # Restart Apache to apply changes
    sudo systemctl restart apache2
    2

    Step 2: Enable mod_rewrite Logging for Debugging

    Turn on detailed rewrite logging to trace the exact sequence of internal redirects causing the loop.

    apache
    # Add to your Apache virtual host config (e.g., /etc/apache2/sites-available/000-default.conf)
    RewriteEngine On
    RewriteLog "/var/log/apache2/rewrite.log"
    RewriteLogLevel 9
    # Test config and restart
    sudo apache2ctl configtest
    sudo systemctl reload apache2
    3

    Step 3: Analyze the Rewrite Log and Fix the Rule

    Examine the rewrite log to identify the circular pattern. A common fix is adding conditions to prevent re-processing.

    bash
    # Tail the rewrite log to see the loop in real-time
    sudo tail -f /var/log/apache2/rewrite.log
    # Example fix: Prevent redirecting already-rewritten URLs
    # In .htaccess, add a condition like:
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
    4

    Step 4: Check for Conflicting Directives in Main Config

    Loops can be caused by interactions between .htaccess and main server config (httpd.conf or apache2.conf).

    bash
    # Search for Alias, Redirect, or ProxyPass directives that might overlap with your .htaccess rules
    grep -r "Alias\|Redirect\|ProxyPass" /etc/apache2/
    # Temporarily comment out suspect directives in main config files, test, and restart.
    5

    Step 5: Implement a Safe RewriteRule Pattern

    Ensure your rewrite rules have proper termination conditions and avoid matching their own target.

    apache
    # BAD: This can create a loop if not carefully conditioned
    RewriteRule ^(.*)$ /index.php?url=$1 [L]
    # BETTER: Add a condition to exclude the target file/folder
    RewriteCond %{REQUEST_URI} !^/index\.php
    RewriteRule ^(.*)$ /index.php?url=$1 [L,QSA]
    6

    Step 6: Clean Up and Verify

    Disable debug logging, re-enable your corrected configuration, and perform a final test.

    bash
    # 1. Remove or comment out RewriteLog directives from main config.
    # 2. Rename your corrected .htaccess file back.
    sudo mv /var/www/html/.htaccess.disabled /var/www/html/.htaccess
    # 3. Restart Apache and test with curl.
    sudo systemctl restart apache2
    curl -I http://your-domain.com/test-page

    Architect's Pro Tip

    "Use `curl -L -v http://yoursite.com` to see the client-side redirect chain. If it's long, Apache is likely generating the internal loops before sending the final response."

    Frequently Asked Questions

    Why did this start happening after an Apache update (e.g., to 2.4.62)?

    Newer Apache versions enforce stricter limits and default behaviors. Changes in mod_rewrite's merging logic for .htaccess files or default `LimitInternalRecursion` can expose previously hidden flawed rules.

    Can I just increase the `LimitInternalRecursion` directive instead of fixing the rules?

    No. Increasing `LimitInternalRecursion` from its default (10) is a dangerous workaround. It masks the configuration error, wastes CPU cycles, and can make your server unresponsive under load.

    The error only happens with HTTPS, not HTTP. Why?

    This strongly points to a misconfigured SSL redirect in your virtual host. Check for conflicting `RewriteCond %{HTTPS}` rules in both port 80 and port 443 configurations that might be bouncing requests between them.

    Related Apache Guides