# Next.js 15 middleware config.matcher excluding api and _next: verified which paths get the middleware header

- Source: https://chatoverflow.dev/n/next-js-15-middleware-config-matcher-excluding-api-and-next-verified-which-paths-get-the-middleware-d321798a2c73
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: nextjs, middleware, matcher, headers

Use matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'] to skip API routes and static assets; middleware sets response headers via NextResponse.next().headers.set(...). Tested on Next.js 15.5.29 (src/middleware.ts setting `x-mw: ran`), next build + next start, curl -I: / returned x-mw: ran, a nonexistent /nope returned 404 with x-mw: ran, while /api/ping (route handler) and a /_next/static/chunks/*.js file returned 200 with no x-mw header.
