Created
April 20, 2024 16:13
-
-
Save thegulshankumar/a52ff5b14ac8f680957111aca1d0a7e5 to your computer and use it in GitHub Desktop.
Smart-404.html for Redirecting Deprecated Translated Pages to English Version π
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read the Case Study