How to Add Wayback Machine Archive Links to 404 Error Pages

When a visitor lands on a 404 error page, they usually leave. But if the missing page was ever saved by the Internet Archive, you can offer them a way to still read it. Adding Wayback Machine archive links to 404 error pages gives visitors a link to the last archived copy of the page, so old links from other sites, bookmarks and search results still lead somewhere useful. Here’s how to do it with a few lines of code, plus when you shouldn’t.

Quick answer: Add a small script to your theme’s 404.php template that asks the Wayback Machine’s Availability API (https://archive.org/wayback/available?url=) whether the missing URL was archived. If it was, show a link to the closest snapshot; if not, show nothing. The Internet Archive also published a ready-made wb404.js script for this.

What the Wayback Machine does

The Wayback Machine (external site) from the Internet Archive has saved snapshots of hundreds of billions of web pages over the years. It’s the best way to see how a page looked in the past. When you delete or move pages and can’t fix every link pointing to them, a link to the archived copy is far better than a dead end.

This is how it looks on our 404 pages:

Wayback Machine archive links on a 404 error page

Option 1: The Internet Archive’s wb404 script

The Internet Archive released a 404 handler for webmasters (external site): two lines to paste into your 404 template.

<div id="wb404"></div>
<script src="https://archive.org/web/wb404.js"></script>

In WordPress, add it to your theme’s 404.php file (use a child theme so updates don’t remove it). If the page has an archived copy, the script shows a link to it. If not, it shows nothing and stays out of the way. It’s an old script, so check it still works on your site after adding it.

Option 2: Use the Wayback Availability API (recommended)

For more control over the wording and styling, call the Wayback Machine’s free Availability API (external site) yourself:

<p id="wayback-link"></p>
<script>
fetch('https://archive.org/wayback/available?url=' + encodeURIComponent(location.href))
  .then(function (r) { return r.json(); })
  .then(function (d) {
    var s = d.archived_snapshots && d.archived_snapshots.closest;
    if (s && s.available) {
      document.getElementById('wayback-link').innerHTML =
        'This page has moved or been removed, but you can ' +
        '<a href="' + s.url + '" rel="nofollow">read an archived copy on the Wayback Machine</a>.';
    }
  });
</script>

The API returns the closest archived snapshot of the current URL. The script runs only after the page has loaded, so it doesn’t slow down your 404 page, and visitors without an archived copy see nothing extra.

Make your 404 page more helpful

An archive link works best as part of a useful 404 page. Also include:

  • A short, friendly message explaining the page wasn’t found.
  • A search box, so visitors can look for what they wanted.
  • Links to your homepage, popular posts and main categories.

When not to add archive links

The code appears on every 404 page that has an archived copy. That’s not always what you want:

  • If you deliberately forced 404 errors to remove thin or penalised content, you probably don’t want to send visitors back to it.
  • If a page is gone for good, a 410 Gone status is clearer for search engines.
  • If a better page exists, use a 301 redirect instead. It helps visitors and keeps the SEO value of backlinks; see how we recovered link juice from deleted subdomains.

Fix broken links on your own site first, too: here’s how to remove broken internal links in WordPress.

Frequently asked questions

Does linking to the Wayback Machine hurt SEO?

No. It’s a link on a 404 page, which search engines don’t index. Adding rel="nofollow" keeps it neutral.

What if my page was never archived?

The script shows nothing. You can ask the Wayback Machine to save important pages now with its Save Page Now feature at web.archive.org.

Can I add this without editing theme files?

Yes. Some 404 page plugins let you add custom HTML or scripts to the 404 page, or use a code snippets plugin that targets 404 pages.

Stuck on a gift? Try our free Gift Idea GeneratorIdeas for anyone by age, job, interests and budget, with Amazon.com and Amazon.in linksFind gifts →

Found this useful? Share it with someone who needs it.

Get our free weekly email: new tech guides and tools, no spam.

New and updated tech guides, a free tool worth bookmarking and one useful pick, once a week. No spam, unsubscribe anytime.

One email a week. Unsubscribe anytime. See our privacy policy.

Related Tech Guides

Leave a Reply

Your email address will not be published. Required fields are marked *

8 Comments

  1. Thanks for sharing this with us. We didn’t know well about 404 Error. So your post can help us.

  2. Honestly I have not thought much of this. On the contrary, I honestly did not even know. Text Archive Links to 404 Error Pages has really helped me to get to know this subject, and I think that will help me in the work that I do. Thanks a lot, and regards

  3. Oh! It’s great info. It may help those users having old/deleted post URL. Recently, I created a custom 404 errors page for blogger blog users but I Wayback Machine has not come to my mind.

    Thanks for this story. Today, I learned something new from your site.

  4. Hii Chandra
    i solve my site 404 problem with awesome article
    Thanks sharing for help
    Have good day