fix(console): redirect /en URLs to the unprefixed English pages (#56593)

This commit is contained in:
Kit Langton
2026-10-17 16:58:54 -07:00
committed by GitHub
Unverified
parent a4163798cd
commit 0168c62ca1
+12
View File
@@ -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