Browser: This page isn't working — redirected you too many times (ERR_TOO_MANY_REDIRECTS) with Next.js middleware / trailing slash
Middleware (or config redirects) keeps redirecting between the same URLs.
ERR_TOO_MANY_REDIRECTS Next.js middlewareThis page isn't working. redirected you too many times Next.jsNext.js redirect loop middlewareThe page isn't redirecting properly Next.jslocalhost redirected you too many times next middleware Meaning
Typical: middleware redirects /dashboard → /login and /login → /dashboard due to inconsistent auth checks, matcher includes the target path, or trailingSlash config conflicts with redirects. Exclude the destination from the matcher (/((?!login|_next|api).*)) and check conditions on both sides. Also www ↔ non-www redirect conflicts with the host/CDN.
Common causes
- Auth redirect ping-pong (login ↔ dashboard)
- Matcher covers the redirect target
trailingSlash: trueplus a redirect removing slash- Host/proxy redirect conflicting with Next redirect
- Cookie not set because of domain/secure settings
⚡ Quick fix
- Exclude the login page from the matcher
- Compare conditions for both redirects
- Check
curl -I -L --max-redirs 5 URLto see the chain
Detailed fix by platform
Linux
curl -sIL --max-redirs 6 https://app.example.com/dashboard | grep -iE "^(HTTP|location)"
How to diagnose
- Chain — Which URLs?
- Matcher — Includes target?
- Cookie — Present?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- Conflicting app and page file was found Next.js: ⨯ Conflicting app and page file was found, please remove the conflicting files to continue: "pages/index.tsx" - "app/page.tsx"
- CORS error calling Next.js API route / route handler Browser: Access to fetch at 'https://api.example.com/api/data' from origin 'https://app.example.com' has been blocked by CORS policy (Next.js route handler)
- Dynamic Code Evaluation not allowed in Edge Runtime Next.js: Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime
Most viewed in Next.js
- NEXT_REDIRECT Next.js: Error: NEXT_REDIRECT (redirect() inside try/catch)
- server-only Next.js: You're importing a component that needs "server-only". That only works in a Server Component
- cookies() should be awaited Next.js 15: Route "/x" used `cookies().get('token')`. `cookies()` should be awaited before using its value
Other ways to find it
Where this error sits
Origin: On your device. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026