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 <cursoragent@cursor.com>
This commit is contained in:
Alireza Hassani
2026-08-29 23:21:37 +03:30
co-authored by Cursor
parent 02aaf61bb6
commit 7034deda89
+6 -3
View File
@@ -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 = {