Keep the query string on language-code redirects (#64138) · github/docs@f075b68 · GitHub
Skip to content

Commit f075b68

Browse files
heiskrCopilot
andauthored
Keep the query string on language-code redirects (#64138)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: bf5940de-658e-4a1a-bffa-3018fb78b138
1 parent eddaaab commit f075b68

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

‎src/languages/tests/redirects.ts‎

Lines changed: 2 additions & 0 deletions

‎src/redirects/middleware/language-code-redirects.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ export default function languageCodeRedirects(
3636
const [code, pattern] = matched
3737
if (code && pattern) {
3838
defaultCacheControl(res)
39-
return res.safeRedirect(301, req.path.replace(pattern, `/${code}`))
39+
// Keep the query string so search terms and selectors such as apiVersion survive.
40+
const queryIndex = req.url.indexOf('?')
41+
const query = queryIndex === -1 ? '' : req.url.slice(queryIndex)
42+
return res.safeRedirect(301, req.path.replace(pattern, `/${code}`) + query)
4043
}
4144
}
4245
return next()

‎src/redirects/tests/unit/language-code-redirects.ts‎

Lines changed: 14 additions & 7 deletions

0 commit comments

Comments
 (0)