fix: handle legacy redirects and media previews

This commit is contained in:
Codex
2026-06-02 11:32:49 +08:00
parent 5a59fcd96b
commit efab08ea26
12 changed files with 251 additions and 67 deletions
+2 -1
View File
@@ -2,6 +2,7 @@ import createMiddleware from 'next-intl/middleware'
import type { NextRequest } from 'next/server'
import { NextResponse } from 'next/server'
import { defaultLocale, locales } from './i18n/config'
import { getSiteUrl } from './lib/seo'
const intlMiddleware = createMiddleware({
locales: [...locales],
@@ -39,7 +40,7 @@ export default function middleware(request: NextRequest) {
if (!hasLocalePrefix) {
const locale = shouldUseSimplifiedChinese(request) ? 'zh' : 'en'
const url = request.nextUrl.clone()
const url = new URL(request.nextUrl.pathname, getSiteUrl())
url.pathname = `/${locale}${pathname === '/' ? '' : pathname}`
url.search = search
return NextResponse.redirect(url)