Internal redirect loops: Nginx “rewrite or internal redirection cycle” and Apache AH00124
Updated 25 November 2026 · By Brent Alexis
Short answer: the server sent a request back to itself, the new path matched the same rule, and after 10 rounds it gave up with a 500. On a single-page app (React, Vue, Angular) the usual cause is a fallback to /index.html when index.html isn't there, often because the build wasn't uploaded yet. Check the file exists, then end the fallback with =404 on Nginx. On Apache, use rules that skip real files, so they can't match their own result. Raising the limit doesn't fix a loop.
Tested on the official nginx Docker image (Nginx 1.30.8), Debian 12 (Nginx 1.22.1) and Debian 12 Apache 2.4.71, with ProxyForge's own Config Generator output for a static site: 46 checks. How it's tested
- The log lines
- Single-page app: 404 when you refresh a page
- Nginx: the fallback loops when index.html is missing
- Nginx: a rewrite that matches its own result
- Apache: AH00124 and the right rules
- Why raising the limit doesn't help
- Apache FallbackResource: AH00125
The log lines
The visitor sees 500 Internal Server Error. The error log says it was a loop:
| The error log says | Cause |
|---|---|
rewrite or internal redirection cycle while internally redirecting to "/ | Nginx: try_files falls back to a file that isn't there (below) |
rewrite or internal redirection cycle while processing "/ | Nginx: a rewrite ... last that matches its own result (below) |
AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error | Apache: a RewriteRule that keeps matching (below) |
AH00125: Request exceeded the limit of 10 subrequest nesting levels | Apache: FallbackResource pointing at a missing file (below) |
Nginx's log is /var/log/nginx/error.log (docker logs in the official image); Apache's is /var/log/apache2/error.log on Debian and Ubuntu. Both Nginx versions logged the same lines, word for word.
Single-page app: 404 when you refresh a page
This is where most of these loops start. The Config Generator's output for a static site serves files that exist and gives a 404 for anything else:
server {
listen 80;
server_name example.com www.example.com;
root /var/www/example.com;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
A single-page app only has one real page, index.html. Links inside the app work, but refreshing /dashboard or opening it from a bookmark asks the server for a file called dashboard. In the lab that was a 404 on Nginx, and on Apache with the generator's virtual host.
The fix is to send every path that isn't a real file to index.html, and let the app pick the page. Change the try_files line to:
try_files $uri $uri/ /index.html =404;
Checked with that line: /dashboard got the app, and real files such as /assets/app.js were still served. Then test and reload:
sudo nginx -t && sudo systemctl reload nginx
One side effect to know about: a missing asset, such as a script with an old file name, also gets the app with a 200, not a 404. In the browser's console that shows up as a script that “doesn't run” rather than a missing file.
The Config Generator can now write this for you: choose Static site and tick Single-page app. The Nginx output uses the try_files line above; the Apache output (.htaccess or virtual host) uses the RewriteCond rules below. All three were tested on 25 November 2026 exactly as the generator writes them: /dashboard got the app, real files were still served, and with index.html missing it was a 404, not a loop.
Nginx: the fallback loops when index.html is missing
Most answers give the line without =404 at the end:
try_files $uri $uri/ /index.html;
It works the same while index.html is there. But with the folder empty (the config deployed before the build was uploaded, or the build in dist/ one level down), every page was a 500, and the log said:
[error] rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 127.0.0.1, server: example.com, request: "GET /dashboard HTTP/1.1", host: "example.com"
The last item in try_files is a redirect, not a file check. Nginx redirects to /index.html, which isn't there, so the same line redirects it again, until Nginx stops the loop. With =404 at the end, /index.html becomes a file check instead: the same empty folder gave a plain 404 and nothing in the log. So the real fix for this error is to put the files where root points (ls -la /var/www/example.com), and the =404 stops a missing build from turning into a loop.
Nginx: a rewrite that matches its own result
The other way to loop is a rewrite whose new path matches the same location again. This line inside location / passed nginx -t:
rewrite ^/(.*)$ /app/$1 last;
/page became /app/page, which is still in location /, so it became /app/app/page, and so on. The visitor got a 500, and the log shows the path growing:
[error] rewrite or internal redirection cycle while processing "/app/app/app/app/app/app/app/app/app/app/app/page"
last means “start over and find the location again”. With break instead, Nginx keeps the new path and stays in the same block: no loop (in the lab it was then a 404, because there was no /app folder). Use break, or a pattern that can't match the new path (not lab-tested).
Apache: AH00124 and the right rules
The generator's Apache virtual host for a static site (HTTPS and Gzip unticked):
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com
<Directory /var/www/example.com>
Options -Indexes
AllowOverride None
Require all granted
</Directory>
DirectoryIndex index.html
</VirtualHost>
A rule that sends everything to index.html without checking first, added inside <Directory> with mod_rewrite enabled, gave a 500:
RewriteEngine On
RewriteRule ^(.*)$ index.html/$1 [L]
[core:error] 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.
Inside <Directory> or .htaccess, [L] only ends this round. Apache then runs the rules again on the new path, index.html/dashboard matches ^(.*)$ too, and it goes round until the limit. These rules checked out in the lab:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.html [L]
Checked: /dashboard got the app, and real files were still served. The two RewriteCond lines skip anything that exists, so index.html itself isn't rewritten again. Unlike the Nginx line without =404, they didn't loop when index.html was missing: with the folder empty it was a plain 404 and no AH00124, because mod_rewrite skips a rewrite that leaves the path unchanged. Enable mod_rewrite with sudo a2enmod rewrite (Debian and Ubuntu) if it isn't already, then:
sudo apachectl configtest && sudo systemctl reload apache2
Changing [L] to [END] on the broken rule also stopped AH00124, because [END] stops the later rounds too. It didn't make the rule right: the page was a 404, for index.html/dashboard.
Why raising the limit doesn't help
The message suggests LimitInternalRecursion. Two things happened in the lab:
- Inside
<Directory>it's not allowed.apachectl configtestrefused it withAH00526: Syntax error ... LimitInternalRecursion not allowed in <Directory> context, and the running config stayed the same. It goes in the<VirtualHost>or the main config. - At virtual-host level with
LimitInternalRecursion 20, the same broken rule was still a 500. The log just saidlimit of 20 internal redirects. A loop never ends on its own, so a higher limit only means more rounds before the same error.
Nginx has no setting for it: the limit of 10 is built into Nginx (its source code; not lab-tested beyond the log above, which shows the path after 10 rewrites). On both servers, fix the rule.
Apache FallbackResource: AH00125
Apache has a one-line alternative to the rewrite rules, from mod_dir (no mod_rewrite needed). Inside <Directory>:
FallbackResource /index.html
Checked: /dashboard got the app, and real files were still served. It isn't safe from a missing build either. With index.html gone, it was a 500 with a different code:
[core:error] AH00125: Request exceeded the limit of 10 subrequest nesting levels due to probable configuration error.
Same cause, same fix: put the files where DocumentRoot points.
Generate a single-page app config for Nginx or Apache →
How to use ProxyForge · FAQ: common errors · Guides · What's new · About