Skip to content

Commit

Permalink
Add basic redirect support
Browse files Browse the repository at this point in the history
Signed-off-by: stianst <stianst@gmail.com>
  • Loading branch information
stianst committed Jan 30, 2025
1 parent 49bdd29 commit 816d5d7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pages/404.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@

</div>

<script src="${links.getResource('js/redirect.js')}" type="text/javascript"></script>

</@tmpl.page>
23 changes: 23 additions & 0 deletions resources/js/redirect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var page = window.location.pathname + window.location.hash;
var openRedirects = new XMLHttpRequest();
openRedirects.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var redirects = this.responseText.split(/\r?\n/);
for (var i = 0; i < redirects.length; i++) {
var redirect = redirects[i].split("=");
if (page.startsWith(redirect[0])) {
var checkRedirect = new XMLHttpRequest();
checkRedirect.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
window.location = checkRedirect.responseURL;
}
}
checkRedirect.open("GET", redirect[1], true);
checkRedirect.send();
break;
}
}
}
};
openRedirects.open("GET", "/resources/redirects", true);
openRedirects.send();
2 changes: 2 additions & 0 deletions resources/redirects
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/docs/latest/security_apps=/guides#securing-apps
/docs/latest/server_installation=/guides.html#server

0 comments on commit 816d5d7

Please sign in to comment.