Skip to content

Commit

Permalink
revert to original, and set limit of 1 try only
Browse files Browse the repository at this point in the history
  • Loading branch information
aakashdinkarh committed Oct 13, 2024
1 parent 5838a01 commit 5ea3d3c
Showing 1 changed file with 23 additions and 37 deletions.
60 changes: 23 additions & 37 deletions 404.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,36 @@
<meta charset="utf-8" />
<title>404 Not Found</title>
<script type="text/javascript">
var pathSegmentsToKeep = 1; // Adjust based on how many path segments you need to keep
var maxRedirects = 1; // Limit to 1 redirect attempt
var pathSegmentsToKeep = 1;

var l = window.location;

// Check the number of redirects from sessionStorage
var maxRedirects = 1;
var redirectCount = parseInt(sessionStorage.getItem('redirects')) || 0;

// If the number of redirects exceeds the limit, show a 404 Not Found message
if (redirectCount >= maxRedirects) {
sessionStorage.removeItem('redirects');
document.body.innerHTML = "<h1>404 Not Found</h1><p>The page you are looking for doesn't exist.</p>";
return;
}

// Increment the redirect count and store it in sessionStorage
redirectCount += 1;
sessionStorage.setItem('redirects', redirectCount);

// Build the new path
var newPath =
l.protocol +
'//' +
l.hostname +
(l.port ? ':' + l.port : '') +
l.pathname
.split('/')
.slice(0, 1 + pathSegmentsToKeep)
.join('/') +
'/?/';

var remainingPath = l.pathname.slice(1).split('/').slice(pathSegmentsToKeep).join('/');

if (l.search) {
newPath += remainingPath.replace(/&/g, '~and~') + '&' + l.search.slice(1).replace(/&/g, '~and~');
} else {
newPath += remainingPath;
}

if (l.hash) {
newPath += l.hash;
}

// Redirect to the new path
l.replace(newPath);
var l = window.location;
l.replace(
l.protocol +
"//" +
l.hostname +
(l.port ? ":" + l.port : "") +
l.pathname
.split("/")
.slice(0, 1 + pathSegmentsToKeep)
.join("/") +
"/?/" +
l.pathname
.slice(1)
.split("/")
.slice(pathSegmentsToKeep)
.join("/")
.replace(/&/g, "~and~") +
(l.search ? "&" + l.search.slice(1).replace(/&/g, "~and~") : "") +
l.hash
);
</script>
</head>
<body></body>
Expand Down

0 comments on commit 5ea3d3c

Please sign in to comment.