diff --git a/src/middleware.ts b/src/middleware.ts index 3403d24..2293ab8 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -16,9 +16,12 @@ export function middleware(request: NextRequest) { ); if (hasLocale || PUBLIC_FILE.test(pathname)) return NextResponse.next(); - const url = request.nextUrl.clone(); - url.pathname = `/${defaultLocale}${pathname === "/" ? "" : pathname}`; - return NextResponse.redirect(url); + // Relative Location keeps the public host; NextURL.origin is the PM2 bind address. + const location = `/${defaultLocale}${pathname === "/" ? "" : pathname}${request.nextUrl.search}`; + return new NextResponse(null, { + status: 307, + headers: { Location: location }, + }); } export const config = {