Next.js Discord

Discord Forum

Middleware matcher not firing for pages

Unanswered
Gray Wagtail posted this in #help-forum
Open in Discord
Gray WagtailOP
export const config: MiddlewareConfig = {
  matcher: [
    '/((?!api|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt|.*\\.(?:png|jpg|jpeg|webp|svg|gif|ico|mp4|webm|css|js)).*)',
  ],
};

Whatever page I go to, this middleware doesn't run. As soon as I remove the matcher it does, so it's clearly in the matcher. This regex allows any path, I verified that myself. So what gives?

1 Reply

Gray WagtailOP
I also tried the recommended one in the docs matcher: ['/((?!api|_next/static|_next/image|.*\\.png$).*)'] and that too gets no hit regardless of page