Files
godot-docs/404.rst
Hugo Locurcio 16e84a8d76 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.).
2025-11-06 20:31:14 +01:00

64 lines
2.3 KiB
ReStructuredText

:github_url: hide
:allow_comments: False
Page not found
==============
.. https://github.com/readthedocs/sphinx-notfound-page
.. raw:: html
<p>
Sorry, we couldn't find that page. It may have been renamed or removed
in the version of the documentation you're currently browsing.
</p>
<p>
If you're currently browsing the
<em>latest</em> version of the documentation, try browsing the
<a href="/en/stable/"><em>stable</em> version of the documentation</a>.
</p>
<p>
Alternatively, use the
<a href="#" onclick="$('#rtd-search-form [name=\\'q\\']').focus()">Search docs</a>
box on the left or <a href="/">go to the homepage</a>.
</p>
<script>
// 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.)
if (window.location.pathname.includes('/en/4.x/')) {
const newUrl = window.location.pathname.replace('/en/4.x/', '/en/stable/');
window.location.replace(newUrl);
}
// Check for redirects if on a currently invalid page.
// This is done in JavaScript, as we exceed Read the Docs' limit for the amount of redirects configurable.
// When testing this feature on a local web server, replace the URL below with just `/_static/redirects.csv`.
fetch("/en/latest/_static/redirects.csv")
.then(response => response.text())
.then(csvText => {
const lines = csvText.trim().split('\n');
for (const line of lines) {
if (!line.trim()) {
continue;
}
const [from, to] = line.split(',').map(s => s.trim());
if (from && to) {
if (window.location.pathname.endsWith(from)) {
if (to.startsWith('https://')) {
window.location.replace(to);
} else {
const newUrl = window.location.href.replace(window.location.pathname, to);
window.location.replace(newUrl);
}
}
}
}
})
.catch(err => {
console.error("Couldn't fetch redirects list:", err);
});
</script>