diff --git a/source/_templates/redirect.html b/source/_templates/redirect.html
index 1e85b7209a7..129af0b68d5 100644
--- a/source/_templates/redirect.html
+++ b/source/_templates/redirect.html
@@ -22,17 +22,34 @@
console.error("invalid fragment: " + fragment);
fragment = "";
}
- if (fragment !== "" && fragment in fragment_redirects) {
- let redirecturl = fragment_redirects[fragment];
+ function redirectTo(redirecturl) {
if (redirecturl.startsWith("/")) {
redirecturl = window.location.origin + redirecturl;
}
window.location = redirecturl;
+ }
+ const hasRedirect = (key) => Object.prototype.hasOwnProperty.call(fragment_redirects, key);
+ if (fragment !== "" && hasRedirect(fragment)) {
+ redirectTo(fragment_redirects[fragment]);
+ } else if (hasRedirect(DEFAULT_PAGE)) {
+ // Fall back to the base-page redirect. Section anchors aren't always
+ // explicitly mapped, but anchor names are generally preserved across a
+ // page move, so carry the original fragment over to the new page rather
+ // than leaving the user on a blank stub.
+ let redirecturl = fragment_redirects[DEFAULT_PAGE];
+ if (fragment !== "" && fragment !== DEFAULT_PAGE) {
+ console.debug("unmapped fragment, falling back to base page: " + fragment);
+ if (redirecturl.indexOf("#") === -1) {
+ redirecturl += "#" + fragment;
+ }
+ }
+ redirectTo(redirecturl);
} else {
if (fragment !== "") {
console.error("unknown redirect: " + fragment);
}
- // TODO: redirect the user to a 404 page or some other page
+ // No redirect could be resolved for this page; send the user to the 404 page.
+ redirectTo("/404.html");
}