From 7034deda89f82b011bf817ac40e37448bcac7744 Mon Sep 17 00:00:00 2001 From: Alireza Hassani Date: Sat, 29 Aug 2026 23:21:37 +0330 Subject: [PATCH] Fix locale redirect staying on majdtrading.com instead of localhost. Next.js builds nextUrl from the PM2 bind address (127.0.0.1:3024), so an absolute redirect sent browsers to https://localhost:3024/fa. Co-authored-by: Cursor --- src/middleware.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 = {