import createMiddleware from "next-intl/middleware"; import {NextResponse, type NextRequest} from "next/server"; import {routing} from "./src/i18n/routing"; const handleI18nRouting = createMiddleware(routing); export default function middleware(request: NextRequest) { const legacyEnglishMarkets = ["/en-ie", "/en-gb", "/en-us"]; const pathname = request.nextUrl.pathname; for (const legacyPath of legacyEnglishMarkets) { if (pathname === legacyPath || pathname.startsWith(`${legacyPath}/`)) { const url = request.nextUrl.clone(); url.pathname = pathname.replace(legacyPath, "/en"); return NextResponse.redirect(url); } } return handleI18nRouting(request); } export const config = { matcher: ["/((?!api|_next|_vercel|.*\\..*).*)"], };