About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.
The visitor sees a 500 Internal Server Error, and the Apache error log holds 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. Apache has followed a chain of internal redirects for one request and cut it off at 10. Apache's per-directory page shows a rewrite rule that keeps matching its own output. Our own reading: raising the limit does not cure that; the rule has to stop matching.
What the error means
An internal redirect is a change of URL that happens inside the server, so the browser's address bar never changes. Apache's documentation for LimitInternalRecursion says it "prevents the server from crashing when entering an infinite loop of internal redirects or subrequests. Such loops are usually caused by misconfigurations." The default is LimitInternalRecursion 10, and the directive is valid in server config and virtual host context only.
In the Apache httpd 2.4.62 source, the function ap_is_recursion_limit_exceeded in server/core.c counts the internal redirects that lead to the current request. When the count reaches the limit it logs this message at error level, and modules/http/http_request.c then ends the request with HTTP_INTERNAL_SERVER_ERROR. The "10" in the message is the configured limit, not a fixed number.
The loop Apache's page documents comes from mod_rewrite in per-directory context. Apache's per-directory rewrite page says: "When a substitution is made in per-directory context, Apache issues a new internal subrequest with the rewritten URL, restarting request processing from the top." In .htaccess files and Directory blocks, the [L] flag means "stop processing the ruleset for this pass", and the rewritten request then meets the same rules again.
The same page names a typical rule that loops: RewriteRule "^(.*)$" "/index.php?q=$1" [L]. A request for /hello becomes /index.php?q=hello, which matches ^(.*)$ again and becomes /index.php?q=index.php, and so on until Apache stops it with a 500.
Likely causes
| Cause | What you see | How to confirm |
|---|---|---|
A catch-all RewriteRule with [L] in .htaccess or a Directory block, with no condition that skips already-rewritten URLs |
Every page returns 500; AH00124 in the error log |
The rule matches everything, such as ^(.*)$, and the file has no RewriteCond lines above it |
A rewrite rule placed in a Directory, If or Location block inside a virtual host |
The same rule behaves differently from one placed directly in the virtual host | Apache's page says such a block "silently" switches to per-directory behaviour, with loop risk |
The [N] flag on a rule |
500 as soon as the rule matches | Apache says [N] restarts the ruleset from the top and "may result in loop" |
Wrong or missing RewriteBase for an application in a subdirectory |
A wrongly resolved URL | The .htaccess sits in a subdirectory and has relative substitutions with no RewriteBase; Apache says the rewritten URL "might resolve incorrectly" |
| Rules inherited from a parent directory | A loop that appeared after a rule set was added in a parent | Look for RewriteOptions Inherit and read the parent's .htaccess as well as the child's |
Prove the cause before changing anything
All of these steps only read.
1. Find the message. The ErrorLog directive names the file; Apache's own example is ErrorLog "/var/log/httpd/error_log". Use the file your configuration names. The GNU manual says "grep prints lines that contain a match for one or more patterns."
grep AH00124 /var/log/httpd/error_log
A good result is one or more lines with AH00124, with timestamps that match the failing requests. No lines means the 500 has another cause.
2. Look at the status the visitor gets. curl's manual says -I, --head will "Fetch the headers only."
curl -I https://www.example.com/hello
A 500 status with a matching AH00124 line in the log points at a loop; the AH00124 line is the proof. The path can be any URL that fails.
3. Read the rules. List every rewrite line in the document root's .htaccess; the path below is the one used in the example. The GNU manual describes -n as "Prefix each line of output with the 1-based line number within its input file."
grep -n "Rewrite" /var/www/example.com/htdocs/.htaccess
Look for a catch-all pattern such as ^(.*)$, the flag [L] at the end, a substitution that starts with /index.php, and the absence of any RewriteCond line above it. Apache's page also shows that in per-directory context a pattern never starts with /, because the directory prefix is stripped before matching.
Apache 2.4 writes rewrite decisions at the trace1 to trace8 log levels, set with LogLevel; the documented example is LogLevel alert rewrite:trace3. The page says: "Do not leave trace-level logging enabled in production."
Fix
Choose the route that matches the rule you found. Both edits act on the rule, not on the limit. Run only one of the two edits below.
First save the current state. The GNU manual says "cp copies files (or, optionally, directories)." Copy .htaccess to a saved name beside it:
cp -p /var/www/example.com/htdocs/.htaccess /var/www/example.com/htdocs/.htaccess.2026-12-04
Stop the loop with the END flag (the documented first choice)
Apache's page calls [END] "the cleanest way to prevent loops". It "stops all further rewrite processing, including subsequent passes" and has been available since Apache 2.3.9. The rewrite flags page adds: "[END] prevents all further rewrite processing, breaking the cycle."
Risk: the next edit changes how every request below this directory is routed. Apache reads .htaccess on every request, so the change is live the moment the file is saved, and a typing mistake returns a 500 for the whole site at once. Make the edit when traffic is low.
Change only the flag at the end of your own rule to [END]; keep your own pattern and substitution. The block shows the sample rule from Apache's page:
RewriteRule "^(.*)$" "/index.php?q=$1" [END]
Check the result. Request the failing URL again and expect a status that is not 500:
curl -I https://www.example.com/hello
Only if you need to back out: copy .htaccess.2026-12-04 back over .htaccess.
Risk: the back-out command overwrites .htaccess with the saved copy. It discards the [END] change and any other edit made to the file since the copy, and the 500 returns if the loop is still in the rule.
cp -p /var/www/example.com/htdocs/.htaccess.2026-12-04 /var/www/example.com/htdocs/.htaccess
Then request the failing URL again with the same check:
curl -I https://www.example.com/hello
Skip URLs that already exist
Apache's second option adds two conditions so the rule is skipped when the request is already for a real file or directory. On the second pass index.php exists, so the !-f condition makes Apache skip the rule. Use it instead of the [END] edit, with the same saved copy .htaccess.2026-12-04.
Risk: the next edit changes how every request below this directory is routed and is live the moment the file is saved; a typing mistake returns a 500 for the whole site at once.
Add the two condition lines directly above your own rule and keep your rule's pattern, substitution and flag as they are. The block shows the sample rule from Apache's page:
RewriteCond "%{REQUEST_FILENAME}" !-f
RewriteCond "%{REQUEST_FILENAME}" !-d
RewriteRule "^(.*)$" "/index.php?q=$1" [L]
Check the result. Request the failing URL again and expect a status that is not 500:
curl -I https://www.example.com/hello
Only if you need to back out: copy .htaccess.2026-12-04 back over .htaccess.
Risk: the back-out command overwrites .htaccess with the saved copy. It discards the two conditions and any other edit made to the file since the copy, and the 500 returns if the loop is still in the rule.
cp -p /var/www/example.com/htdocs/.htaccess.2026-12-04 /var/www/example.com/htdocs/.htaccess
Then request the failing URL again with the same check:
curl -I https://www.example.com/hello
Our own reading: the conditions also make the rule skip requests for images and style sheets that exist, which is usually what a front controller wants.
The simpler directive for a front controller
For routing every unmatched request to one script, Apache's mod_dir page describes FallbackResource /index.php as handling requests that do not map to a file, and the .htaccess page calls it "a simpler and more efficient alternative to mod_rewrite" for that use. It needs AllowOverride Indexes in the context where it is used. Our own reading: it replaces the rewrite rules, so it is a change to take to the site's developer.
Do not raise the limit as the fix
The message itself says to use LimitInternalRecursion "to increase the limit if necessary". Our own reading: a rule that matches its own output loops forever, so a higher limit only lengthens the loop before the same 500. A second number in the directive sets the subrequest nesting depth, which is a separate limit that logs AH00125.
Example (illustrative): on web01, www.example.com serves from /var/www/example.com/htdocs. A developer adds RewriteRule "^(.*)$" "/index.php?q=$1" [L] to that directory's .htaccess. A request for /hello returns 500, and the error log has AH00124. The administrator saves the file as .htaccess.2026-12-04, changes [L] to [END], and curl -I https://www.example.com/hello now returns the status the application gives for that page, and the log shows no new AH00124 line.
Confirm the fix
- Request the failing URL again with
curl -Iand expect the status your application gives, not 500. - Look at the end of the error log: no new
AH00124line should appear after the time of your change. - Request a URL that does not exist and one that does, such as an image. Both should behave as before the rule was added.
What to watch afterwards
- Give every new catch-all rule in
.htaccessor aDirectoryblock either[END]or conditions that skip files that exist. Apache's page recommends[END]as the first choice for breaking this loop. - Apache's page says to use
[R=302](temporary redirect) instead of[R=301]while debugging redirect rules, and to switch to 301 only after the rule is confirmed correct. It says browsers and search engines can keep a 301 for a long time, so a wrong 301 can outlive the fix. - The error log is the place a loop shows first; a count of
AH00124lines per day is a simple signal to add to routine checks.
Read next
Related articles you may want next.
- TroubleshootingApache 500 with "Invalid command 'RewriteEngine'": enable mod_rewrite and AllowOverrideApache 500 "Invalid command 'RewriteEngine', perhaps misspelled ...": load mod_rewrite, allow FileInfo overrides in AllowOverride, verify.Read article
- Hostingnginx 500: rewrite or internal redirection cycle while internally redirecting to "/index.php"nginx 500 with 'rewrite or internal redirection cycle while internally redirecting to /index.php': find the loop in try_files or rewrite and fix it.Read article
- TroubleshootingERR_TOO_MANY_REDIRECTS after turning on HTTPS behind a proxy or CDNRedirect loop after enabling HTTPS behind a proxy or CDN? Trace it with curl -I -L, then fix X-Forwarded-Proto handling or the proxy encryption mode.Read article
Risks and limits
- These commands have not been run or lab-tested.
- The source reading is for tag 2.4.62.
- An
.htaccessedit is live at once and affects the whole directory tree under it. - This message covers internal redirects. A loop the browser reports as too many redirects is an external redirect loop, covered in ERR_TOO_MANY_REDIRECTS after turning on HTTPS behind a proxy or CDN. A 500 that begins with an unknown directive is covered in Apache 500 with "Invalid command 'RewriteEngine'": enable mod_rewrite and AllowOverride. The nginx form of the same fault is covered in nginx 500: rewrite or internal redirection cycle while internally redirecting to "/index.php".
Sources
- Per-directory Rewrites — Apache HTTP Server Project, no date shown, accessed 4 December 2026
- RewriteRule Flags — Apache HTTP Server Project, no date shown, accessed 4 December 2026
- Apache Core Features — Apache HTTP Server Project, no date shown, accessed 4 December 2026
- Apache Module mod_rewrite — Apache HTTP Server Project, no date shown, accessed 4 December 2026
- Apache Module mod_dir — Apache HTTP Server Project, no date shown, accessed 4 December 2026
- httpd/server/core.c at 2.4.62 — Apache Software Foundation source at a fixed tag, no date shown, accessed 4 December 2026
- httpd/modules/http/http_request.c at 2.4.62 — Apache Software Foundation source at a fixed tag, no date shown, accessed 4 December 2026
- cp invocation — GNU Coreutils 9.12 manual, no date shown, accessed 4 December 2026
- GNU Grep 3.12 — GNU Grep manual, no date shown, accessed 4 December 2026
- curl man page — curl project, no date shown, accessed 4 December 2026
This article was originally published on .