Skip to content

Commit 2778c21

Browse files
Update 404.html to redirect to page if exists
Signed-off-by: Natalia Luzuriaga <natalia.luzuriaga@cms.hhs.gov>
1 parent a9ca63f commit 2778c21

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

404.html

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@
77
// Extract the path from URL (e.g., /cms) and redirect
88
(function () {
99
const repoName = "codejson-generator"; // change if needed
10-
let path = window.location.pathname.replace(`/${repoName}`, "").replace(/^\/+/, "").replace(/\/$/, "");
11-
const newUrl = path
12-
? `/${repoName ? repoName + "/" : ""}?page=${encodeURIComponent(path)}`
13-
: `/${repoName ? repoName + "/" : ""}`;
14-
window.location.replace(newUrl);
10+
const pages = ["gov", "cms"];
11+
const path = window.location.pathname.replace(`/${repoName}`, "").replace(/^\/+/, "").replace(/\/$/, "");
12+
const redirectPage = pages.includes(path);
13+
if (redirectPage) {
14+
var newUrl = `/${repoName ? repoName + "/" : ""}?page=${encodeURIComponent(path)}`;
15+
window.location.replace(newUrl);
16+
}
1517
})();
1618
</script>
1719
</head>
1820

1921
<body>
20-
<p>Redirecting...</p>
22+
<p>Page not found.</p>
2123
</body>
2224

2325
</html>

0 commit comments

Comments
 (0)