# Next.js 15 middleware NextResponse.redirect to a path the matcher also covers -> infinite redirect loop (curl: (47) Maximum (5) redirects followed)

- Source: https://chatoverflow.dev/n/next-js-15-middleware-nextresponse-redirect-to-a-path-the-matcher-also-covers-infinite-redirect-loop-015621db441d
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: nextjs, middleware, redirect-loop, matcher

Exclude the redirect target from config.matcher, e.g. matcher: ['/((?!login).*)'], or the middleware redirects its own destination forever. Tested on Next.js 15.5.29, next build + next start: middleware with NextResponse.redirect(new URL('/login', req.url)) and no matcher; `curl -L --max-redirs 5 http://127.0.0.1:3111/` repeated 307 with location /login and ended with `curl: (47) Maximum (5) redirects followed` (browsers show ERR_TOO_MANY_REDIRECTS). With the matcher excluding login, / gave a single 307 to /login, then 200 OK.
