mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-13 19:46:16 +03:00
fix(console): redirect /en URLs to the unprefixed English pages (#56593)
This commit is contained in:
committed by
GitHub
Unverified
parent
a4163798cd
commit
0168c62ca1
@@ -13,6 +13,18 @@ export default createMiddleware({
|
||||
url.pathname = strip(url.pathname)
|
||||
if (/^\/changelog\/?$/.test(url.pathname))
|
||||
return new Response(null, { status: 301, headers: { Location: "/changelog" } })
|
||||
// English pages live at unprefixed URLs, so /en/... would be a duplicate of every page.
|
||||
// /data keeps /en because it redirects unprefixed visits by cookie and Accept-Language.
|
||||
// Collapse leading slashes so /en//example.com can't become a protocol-relative redirect.
|
||||
if (
|
||||
locale === "en" &&
|
||||
(event.request.method === "GET" || event.request.method === "HEAD") &&
|
||||
!/^\/data(\/|$)/.test(url.pathname)
|
||||
)
|
||||
return new Response(null, {
|
||||
status: 301,
|
||||
headers: { Location: `${url.pathname.replace(/^\/+/, "/")}${url.search}` },
|
||||
})
|
||||
const request = new Request(url, event.request)
|
||||
request.headers.set(LOCALE_HEADER, locale)
|
||||
event.request = request
|
||||
|
||||
Reference in New Issue
Block a user