Skip to content

Instantly share code, notes, and snippets.

@thegulshankumar
Created April 20, 2024 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thegulshankumar/a52ff5b14ac8f680957111aca1d0a7e5 to your computer and use it in GitHub Desktop.
Save thegulshankumar/a52ff5b14ac8f680957111aca1d0a7e5 to your computer and use it in GitHub Desktop.
Smart-404.html for Redirecting Deprecated Translated Pages to English Version πŸš€
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>example.com</title>
<style>
body, html {
height: 100%;
margin: 0;
padding: 0;
}
#message {
display: none;
position: absolute;
top: 30%;
left: 50%;
transform: translate(-50%, -50%);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
color: #333;
max-width: 80%;
}
#message h1 {
font-size: 36px;
margin-bottom: 20px;
}
#message p {
font-size: 20px;
margin-bottom: 20px;
}
#message a {
color: #007bff;
text-decoration: underline;
}
@media only screen and (max-width: 768px) {
#message h1 {
font-size: 24px;
}
#message p {
font-size: 16px;
}
}
</style>
<script>
// Get the current URL
var currentUrl = window.location.href;
// Grab the hostname dynamically
var hostname = window.location.hostname;
// Check if the current URL has a language code in it
var languageRegex = new RegExp("^https?://" + hostname + "/(az|fr|hi|id|pt|ru|es|tr|ar|bn|zh-CN|nl|fy|de|gu|it|ms|ml|mr|ta|te|th|vi)/(.*)$");
var match = currentUrl.match(languageRegex);
if (match) {
// Extract the path after the language code
var pathAfterLanguageCode = match[2];
// Redirect to the new URL without the language code
var newUrl = "https://" + hostname + "/" + pathAfterLanguageCode;
window.location.href = newUrl;
} else {
// Add an event listener for DOMContentLoaded to show the message element
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("message").style.display = "block";
});
}
</script>
</head>
<body>
<div id="message">
<h1>Page not found</h1>
<p>Sorry, we couldn't find any such page. 😒 </p>
<p>Kindly visit our <strong><a href="/">homepage</a></strong> to find what you are looking for.</p>
</div>
</body>
</html>
@thegulshankumar
Copy link
Author

Read the Case Study

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment