ERR_TOO_MANY_REDIRECTS (Next.js middleware) Next.js Origin: On your device Last updated 5 Nov 2026

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.

Exact message you may see 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
Seen on: Next.js

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: true plus a redirect removing slash
  • Host/proxy redirect conflicting with Next redirect
  • Cookie not set because of domain/secure settings

⚡ Quick fix

  1. Exclude the login page from the matcher
  2. Compare conditions for both redirects
  3. Check curl -I -L --max-redirs 5 URL to see the chain

Detailed fix by platform

Linux

  1. curl -sIL --max-redirs 6 https://app.example.com/dashboard | grep -iE "^(HTTP|location)"

How to diagnose

  1. Chain — Which URLs?
  2. Matcher — Includes target?
  3. 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:

Where this error sits

Origin: On your device. Errors that are often confused with or caused by this one (click to open):

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" (Next.js)Conflicting app and p…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) (Next.js)CORS error calling Ne…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 (Next.js)Dynamic Code Evaluati…Middleware matcher: Capturing groups are not allowed — Next.js: Error: Invalid middleware found. Capturing groups are not allowed in matcher / `matcher` values must start with `/` (Next.js)Middleware matcher: C…next build: fetch failed ECONNREFUSED (build-time API) — Next.js: Error occurred prerendering page "/blog" TypeError: fetch failed { cause: Error: connect ECONNREFUSED 127.0.0.1:3000 } (Next.js)next build: fetch fai…next build: JavaScript heap out of memory — Next.js: FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory (during next build) (Next.js)next build: JavaScrip…NO_SECRET — NextAuth / Auth.js: [next-auth][error][NO_SECRET] Please define a `secret` in production / MissingSecret (Authentication)NO_SECRETThe edge runtime does not support Node.js module — Next.js: The edge runtime does not support Node.js 'crypto' module / A Node.js module is loaded ('fs') which is not supported in the Edge Runtime (Next.js)The edge runtime does…ERR_TOO_M…

Explore the map of this error Full error map →

🧠 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.