DEV Community

seotto.com
seotto.com

Posted on

How to find soft 404s: pages that return 200 with a 'not found' body (a Python script over logs and HTML)

Automated technical SEO checks that catch indexing blocks and deploy regressions — seotto.com

A real 404 (or 410) is a clean signal: this URL is not a document. A soft 404 is a page that says "not found", "no results", "this product is gone", or shows an empty shell, and still returns 200. Users get the message. Crawlers get a document they may try to index, or spend crawl budget on, or report weeks later as a soft 404 in Search Console.

They show up after SPA fallbacks ("every path serves index.html"), after deleted products that were given a polite template, and after search pages with no matches. Here is how to find yours before Search Console does.

Start from URLs that already look suspicious

Access logs are a good prior: paths that Googlebot (or users) hit and that should be gone, plus paths that are just odd. Combined with a fetch, you can flag bodies that look like not-found pages.

import re
import sys
from collections import Counter

import requests

# Tight, boring signals. Add your own template strings.
PATTERNS = [
    re.compile(r"page not found", re.I),
    re.compile(r"we couldn't find", re.I),
    re.compile(r"no results for", re.I),
    re.compile(r"this product (is no longer available|has been removed)", re.I),
    re.compile(r"<title>[^<]*404[^<]*</title>", re.I),
]

UA = {"User-Agent": "soft-404-check/1.0"}

def inspect(url):
    try:
        r = requests.get(url, timeout=20, allow_redirects=False, headers=UA)
    except requests.RequestException as e:
        return "ERROR", type(e).__name__, ""
    body = r.text[:20000]
    hits = [p.pattern for p in PATTERNS if p.search(body)]
    if r.status_code == 200 and hits:
        return "SOFT404", r.status_code, ";".join(hits)
    if r.status_code == 200 and len(body.strip()) < 500:
        return "THIN200", r.status_code, f"len={len(body)}"
    return "OK", r.status_code, ""

if __name__ == "__main__":
    counts = Counter()
    for line in sys.stdin:
        url = line.strip()
        if not url:
            continue
        flag, status, detail = inspect(url)
        counts[flag] += 1
        if flag != "OK":
            print(f"{flag}\t{status}\t{url}\t{detail}")
    print("#", dict(counts), file=sys.stderr)
Enter fullscreen mode Exit fullscreen mode

Feed it URLs from a sitemap, from a log extract, or from a list of deleted slugs. I like this extract as a first cut: the paths that already 404 sometimes (so a load balancer is confused), and the paths Googlebot requested that are not in the sitemap.

What to treat as a soft 404

A 200 whose visible message is "not found". Your 404 template served under the wrong status is the textbook case. In many frameworks this is return render(request, "404.html") without status=404.

A SPA fallback. Unknown routes render the app shell with 200, and the client then shows "not found". Curl will see a generic title and a short or generic body; Googlebot may see the same, or a rendered not-found, still with 200. The fix is for the server (or the prerenderer) to return 404 for unknown routes.

Empty or "no results" search and filter pages that are reachable with arbitrary query strings. These can be 200 if you want humans to refine a search, but they should not be in the sitemap, should usually be noindex, and should not be linked as ordinary documents.

Deleted products that "helpfully" 200. A discontinued product can 200 with a useful successor, or 301 to the successor, or 404/410. A 200 with "this item is gone" and no unique reason to exist is a soft 404.

The script's THIN200 flag is a hint, not a verdict. Some real pages are short. Read a sample before you mass-change status codes.

Fixing them, once you have a list

  1. Return a real 404 or 410 for URLs that are gone, with the same template you already show. One line in the framework is often the whole fix.
  2. For SPAs, configure the origin (nginx, Netlify, Vercel, S3+CloudFront) so only known routes serve the app; unknown ones should 404, or the app should prerender a 404 status.
  3. For "gone, but we have a replacement", prefer a 301 to that replacement if it is stable, and unique.
  4. Remove the URLs from the sitemap and from internal links. A correct 404 still wastes crawl budget if you keep advertising the URL.
  5. Do not use noindex as a substitute for 404 on things that are truly gone, unless you have a short transition reason. noindex plus 200 still looks like a document.

A soft 404 is a template and a status code disagreeing, which is exactly the kind of regression a deploy can introduce on a whole section at once. seotto.com checks for indexing and status problems after you ship, so a 404 template that started coming back as 200, or an SPA fallback that swallowed unknown paths, gets caught quickly.

Where this sits next to Search Console

Search Console's "Soft 404" report is useful and late, and it will not list every URL. Your own logs plus a fetch are earlier, and they catch the template you shipped this morning. After you fix a cluster, the report will lag; judge by curl and by URL Inspection on a sample, not only by the chart going to zero the same day.

Add the check to CI for templates you already know about (the official 404 page, requested as a known missing path, must be 404), and run the log-based scan on a schedule for the long tail. A single CI assertion would have caught the classic render("404.html") without a 404 status, which is still the soft 404 I see most often after a framework upgrade.

Related reading

Where have soft 404s shown up on your sites — a framework default, a SPA fallback, or a deleted-product template — and did Search Console see them before you did?

Top comments (0)