handle uppercase paths (#3740)

This commit is contained in:
Deborah Barnard 2025-10-03 12:02:36 +01:00 committed by GitHub
parent 35af91b7a5
commit b7ab8773a1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,7 +2,44 @@
{% block htmltitle %}
<title>404</title>
{% endblock %}
{% block extrahead %}
<script>
// Create an object containing redirects to headings
const redirects = {
};
(function redirect(){
const incomingPath = window.location.pathname;
const hasExtension = /\.[a-zA-Z0-9]+$/.test(incomingPath);
// handle uppercase URLs
if (incomingPath !== incomingPath.toLowerCase()) {
const lowercasePath = incomingPath.toLowerCase();
window.location.href = `${window.location.origin}${lowercasePath}`;
return;
}
// handle missing trailing `/`
if (!incomingPath.endsWith('/') && !hasExtension) {
window.location.href = `${window.location.origin}${incomingPath}/`;
return;
}
// handle redirects for headings
const currentPath = incomingPath + (window.location.hash ? window.location.hash : '');
const redirectUrl = redirects[currentPath];
if (redirectUrl) {
window.location.href = `${window.location.origin}${redirectUrl}`;
return;
}
})();
</script>
{% endblock %}
{% block content %}
<h1>404 - Page not found</h1>
<h2>Go <a href="/">home</a></h2>
{% endblock %}
{% endblock %}