Skip to content

Instantly share code, notes, and snippets.

@mikepianka
Last active July 29, 2022 17:55
Show Gist options
  • Save mikepianka/f8ecaa0016682b811ef4b4e7217e15df to your computer and use it in GitHub Desktop.
Save mikepianka/f8ecaa0016682b811ef4b4e7217e15df to your computer and use it in GitHub Desktop.
Simple HTML Redirect
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Redirecting...</title>
</head>
<body onload="redirect()">
<p>
If you are not automatically redirected; follow this
<a href="#" onclick="redirect()">link</a>
</p>
</body>
<script>
function redirect() {
const destination = "v3";
const rootURL = window.location.href.split("?")[0];
let url;
if (rootURL.includes("index.html")) {
url = `${rootURL.replace("index.html", "")}${destination}/${
window.location.search
}`;
} else {
url = `${rootURL}${destination}/${window.location.search}`;
}
window.location.replace(url);
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment