In case if your site goes down, and you don't have a mirror host for your content, the wayback machine from archive.org provides you with such a thing you can make use of.
Just provide your http server or web framework to detect an error (in PHP you can use the functions set_error_handler
and set_exception_handler
) and redirect to a page that will redirect you, using Javascript, to the corresponding archived content at the WayBackMachine.
The following code does the job:
function archiveorgcacheurl() {
origurl = location.href;
url = new URL(origurl);
console.log(url);
return "https://web.archive.org/web/" + url.protocol + "//" + url.hostname;
}
Insert the following code at the bottom of your error page html:
<script type="text/javascript">
setTimeout(function() {
location.href = archiveorgcacheurl();
},5000);
</script>
After five seconds, it will redirect automatically to the mirrored copy at the wayback machine.
In case you don't want your users to wait this time lapse you can provide a link or button with the following html snippet:
While the error is not solved you can visit a mirrored copy at <A href="javascript:" onclick="this.href=archiveorgcacheurl()">WaybackMachine Cache Page</A>
<h2>Redirecting you automatically... Please wait...</h2>
The complete code for the html page is in the Gist below: