Skip to content

Commit 1ffd71c

Browse files
committed
Fix RTD language switcher redirecting to nonexistent /en/4.x/ branch
If we were redirected to `/en/4.x/` as a result of the RTD language selector, redirect to `/en/stable/` instead, as English does not have a `4.x` branch. For maintenance reasons, non-English languages have a single `4.x` branch that is the counterpart of `4.3`, `4.4`, `4.5` and so on.).
1 parent 5e68807 commit 1ffd71c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

404.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ Page not found
2424
</p>
2525

2626
<script>
27+
// If we were redirected to `/en/4.x/` as a result of the RTD language selector,
28+
// redirect to `/en/stable/` instead, as English does not have a `4.x` branch.
29+
// (For maintenance reasons, non-English languages have a single `4.x` branch
30+
// that is the counterpart of `4.3`, `4.4`, `4.5`, and so on.)
31+
if (window.location.pathname.includes('/en/4.x/')) {
32+
const newUrl = window.location.pathname.replace('/en/4.x/', '/en/stable/');
33+
window.location.replace(newUrl);
34+
}
35+
2736
// Check for redirects if on a currently invalid page.
2837
// This is done in JavaScript, as we exceed Read the Docs' limit for the amount of redirects configurable.
2938
// When testing this feature on a local web server, replace the URL below with just `/_static/redirects.csv`.

0 commit comments

Comments
 (0)