ERR_TOO_MANY_REDIRECTS
nextjs
routing_error
ai_generated
true
Error: ERR_TOO_MANY_REDIRECTS / redirect loop in middleware
ID: nextjs/middleware-redirect-loop
90%Fix Rate
90%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 14 | active | — | — | — |
Root Cause
Middleware redirects to a URL that triggers the middleware again, causing infinite loop.
genericWorkarounds
-
95% success Add matcher config to exclude the redirect destination from middleware
export const config = { matcher: ['/((?!login|_next|api|static).*)'] };Sources: https://nextjs.org/docs/app/building-your-application/routing/middleware#matcher
-
92% success Check for the redirect destination in the condition: if (url !== '/login') redirect('/login')
if (url !== '/login') redirect('/login')Sources: https://nextjs.org/docs/app/building-your-application/routing/middleware
Dead Ends
Common approaches that don't work:
-
Add a redirect counter in cookies
75% fail
Over-engineering — fix the matcher config instead
-
Disable the middleware temporarily
70% fail
Doesn't fix the issue — it'll come back when re-enabled
Error Chain
Frequently confused with: