nginx
config_error
ai_generated
true
nginx: rewrite or internal redirection cycle while processing "/index.html"
ID: nginx/rewrite-loop-detected
88%Fix Rate
90%Confidence
3Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1 | active | — | — | — |
Root Cause
Infinite redirect loop in nginx rewrite rules or try_files. Request bounces between locations or rewrites indefinitely.
genericWorkarounds
-
92% success Add a break or last flag to stop rewrite processing
rewrite ^/old(.*)$ /new$1 last; # 'last' restarts location matching; 'break' stops all rewriting
Sources: https://nginx.org/en/docs/http/ngx_http_core_module.html
-
90% success Use return instead of rewrite for simple redirects
return 301 https://$host$request_uri; # return is simpler and cannot loop within the same server block
-
82% success Use 'if' with specific conditions to prevent recursive matches
if ($request_uri !~ ^/new) { rewrite ^/(.*)$ /new/$1 last; } # guard against re-matching
Dead Ends
Common approaches that don't work:
-
Add more rewrite rules to try to break the loop
82% fail
Adding rewrites to fix rewrites increases complexity. Simplify the existing rules instead of layering more.
-
Use proxy_pass to localhost to escape the rewrite loop
90% fail
Proxying to self creates a new request that hits the same rewrite rules, causing the same loop.