# Browser: This page isn't working — redirected you too many times (ERR_TOO_MANY_REDIRECTS) with Next.js middleware / trailing slash

**Code:** `ERR_TOO_MANY_REDIRECTS (Next.js middleware)` · **Category:** Next.js · **Seen on:** Next.js

Middleware (or config redirects) keeps redirecting between the same URLs.

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/nextjs/middleware-redirect-loop)
