正解は「config.matcherで適用するパスパターンを指定する」です。Next.jsのMiddlewareはデフォルトで全リクエストに対して実行されます。_next/staticや_next/imageなどの静的アセットにまでMiddlewareが適用されると、パフォーマンスの低下や意図しないリダイレクトが発生します。middleware.tsにexport const config = { matcher: ["/dashboard/:path*", "/api/:path*"] }のようにmatcherを設定することで、Middlewareを特定のパスのみに限定できます。また、matcher内では正規表現も使用可能で、/((?!api|_next/static|_next/image|favicon.ico).*)のように除外パターンも記述できます。