Skip to content

Instantly share code, notes, and snippets.

@mhajder
Created July 18, 2020 20:48
Show Gist options
  • Save mhajder/c182bb8cda3a93f408b9e922d2f15ad3 to your computer and use it in GitHub Desktop.
Save mhajder/c182bb8cda3a93f408b9e922d2f15ad3 to your computer and use it in GitHub Desktop.
Redirect to the main domain from subdomains.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
</head>
<body>
<script>
function getDomainName(hostName) {
return hostName.substring(hostName.lastIndexOf(".", hostName.lastIndexOf(".") - 1) + 1);
}
setTimeout(function () {
location.href = "http://" + getDomainName(window.location.hostname);
}, 0)
throw 404;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment