BYTESLIP ← Back
Knowledge Base // Tutorial 123

Make a Custom 404 Page That Still Returns 404, and Fix Soft 404s

Difficulty: Easy ~20 min .htaccess · Apache · LiteSpeed

A friendly “page not found” page keeps visitors on your site. If the server sends it with a 200 OK status, though, Google treats it as a soft 404: an error page that claims to be a real page. On Apache and LiteSpeed shared hosting, one line in .htaccess decides which you get. This guide builds the page, adds the right status for missing, removed and moved URLs, and gives you a curl script to prove it.

Missing URL to a real 404 status Four tiles: missing URL, ErrorDocument pointing at /404.html, status 404, curl check. MISSING URL ERRORDOCUMENT /404.HTML STATUS 404 CURL CHECK
Safety // Read First

Warnings

ImportantA typo in .htaccess can take the whole site down with a 500 error, so back it up first. Never point ErrorDocument at a full URL like https://example.com/404.html. Apache then sends a redirect instead of the 404, and Apache’s own docs warn this confuses robots that check status codes. In our test it returned 302.

Checklist // Before You Start

What You Need

How this was tested: On a local Apache 2.4.71 server with the exact .htaccess block below: a missing URL, both at the root and four folders deep, returned 404 with the custom page; the removed URL returned 410 with and without its trailing slash; the moved URL returned one 301; and /404.html itself returned 200 with noindex. Pointing ErrorDocument at a full URL returned 302. In headless Chrome, the page’s root-relative CSS loaded from a deep missing URL, and a relative path failed with a 404. status_check.sh passed the good setup and flagged a broken one. A live LiteSpeed site also returned 404 with its own custom page. LiteSpeed’s Apache migration FAQ shows ErrorDocument working in .htaccess.

Walkthrough // Steps 01–05

Check → build the page → .htaccess → test → fix soft 404s

All of this is static: one HTML file and a few lines of .htaccess.

  1. Step 1: Check what a missing page returns now

    curl -s -o /dev/null -w '%{http_code}\n' https://example.com/no-such-page-12345/

    You want 404. If you get 200, every typo’d link on the web gives Google a soft 404. A common cause is a rewrite rule that sends every unknown URL to the home page. If you get 301 or 302, look for a full-URL ErrorDocument or a catch-all redirect.

  2. Step 2: Build the 404 page

    Google’s tips for a custom 404 page: say clearly that the page can’t be found, keep the same look and navigation as the rest of the site, link to popular pages and the home page, and consider a way to report the broken link. Save this as public_html/404.html and replace the example names and links with yours:

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Page not found | Example Site</title>
    <meta name="robots" content="noindex">
    <link rel="stylesheet" href="/css/site.css">
    </head>
    <body>
    <main>
    <h1>Sorry, that page isn't here</h1>
    <p>It may have moved, or the link may have a typo. Try one of these:</p>
    <ul>
    <li><a href="/">Home page</a></li>
    <li><a href="/tutorials/">All tutorials</a></li>
    </ul>
    <p>Found a broken link? <a href="mailto:hello@example.com">Tell us</a>.</p>
    </main>
    </body>
    </html>
    • Use root-relative paths (/css/site.css, not css/site.css). The server shows this page at whatever URL was missing, so in our test a relative path broke the CSS on /tutorials/a/b/missing/.
    • Keep the noindex tag. Missing URLs get a real 404, but /404.html opened directly returns 200. The tag keeps that copy out of Search.
  3. Step 3: Add the error rules to .htaccess

    Back up first (in File Manager, copy .htaccess to .htaccess.bak). Then add this block, using your own paths in place of the two example rules:

    # --- Error pages: local paths keep the real status code ---
    ErrorDocument 404 /404.html
    ErrorDocument 410 /404.html
    
    RewriteEngine On
    # Removed for good, no replacement: 410 Gone
    RewriteRule ^tutorials/old-guide/?$ - [G]
    # Moved: one 301 hop to the new address
    RewriteRule ^tutorials/old-name/?$ /tutorials/new-name/ [R=301,L]
    • ErrorDocument 404 /404.html: a local path, so Apache shows the page and keeps the 404 status.
    • [G]: mod_rewrite’s “gone” flag, which returns 410. Use it for pages you removed on purpose with no replacement.
    • [R=301,L]: one permanent redirect for a page that moved. Google says to use a 301 when a page has moved or has a clear replacement.

    If your .htaccess already has a RewriteEngine On line, you don’t need a second one; put the rules after it. For trailing-slash and index.html redirects, see Clean URLs, a Correct sitemap.xml and a Sane robots.txt.

  4. Step 4: Upload, then test every status

    Save this as status_check.sh and edit the two example paths to match your rules:

    #!/usr/bin/env bash
    # Usage: bash status_check.sh https://example.com
    site="${1%/}"
    check() {  # path, expected status
      got=$(curl -s -o /dev/null -w '%{http_code} %{redirect_url}' "$site$1")
      case "$got" in
        "$2"*) echo "OK   $got  $1" ;;
        *)     echo "FIX  $got  $1  (expected $2)" ;;
      esac
    }
    check "/no-such-page-$RANDOM$RANDOM/" 404
    check "/tutorials/old-guide/" 410
    check "/tutorials/old-name/" 301
    curl -s "$site/404.html" | grep -q 'content="noindex"' \
      && echo "OK   404.html has noindex" || echo "FIX  404.html has no noindex tag"
    bash status_check.sh https://example.com

    A passing run on our test server looks like this (its address is replaced with example.com):

    OK   404   /no-such-page-2731819044/
    OK   410   /tutorials/old-guide/
    OK   301 https://example.com/tutorials/new-name/  /tutorials/old-name/
    OK   404.html has noindex

    Any FIX line shows what came back and what was expected. If the site shows a 500 error, restore .htaccess.bak and check the block for typos.

  5. Step 5: Fix the soft 404s Google already found

    In the Page indexing report, open Soft 404 and inspect an example URL. In URL Inspection, run Test live URL, then View tested page, and look at the screenshot. Google lists three cases:

    • The page is gone: return 404 or 410. The block above does this.
    • The page moved: 301 to the new address.
    • The page should work: it probably didn’t load properly for Googlebot. Google names blocked resources (robots.txt), too many resources, server errors, and slow or very large resources. A bot-check page served with 200 can also look like this; see Check What Googlebot Sees.

    When all of them are fixed, click Validate fix on the Soft 404 reason.

Pro Tip

Find the old links that still get hits

Questions // FAQ

FAQ

Should I return 404 or 410?

Either is fine. Google’s docs say all 4xx codes except 429 are treated the same: the content doesn’t exist, and the URL is removed from the index if it was there. Use 410 when you want your own records to say “removed on purpose”.

Do 404 errors hurt my rankings?

Google’s Page indexing help says 404s aren’t necessarily a problem if the page was removed with no replacement. They’re only a problem when a page you want indexed returns one.

Can I just redirect every missing page to the home page?

Google’s advice is 404 or 410 when there’s no replacement and a 301 only when a page moved or has a clear replacement. A helpful 404 page does the job for visitors.

Does this work on LiteSpeed?

Yes. LiteSpeed’s Apache migration FAQ shows ErrorDocument in .htaccess, and RewriteRule is on its list of supported .htaccess directives.

Keep Reading
Sources // Verified

Official docs

Soft 404 definition, the three fixes and custom 404 tips: Troubleshoot Google Search crawling errors. 4xx handling: How HTTP status codes affect Google’s crawlers. Soft 404 and 404 reasons: Page indexing report. ErrorDocument and the full-URL redirect warning: Apache ErrorDocument. The G flag: mod_rewrite flags. LiteSpeed: Apache to LiteSpeed migration FAQ and LiteSpeed .htaccess directives. Hidden files: cPanel File Manager.

← All Tutorials Byteslip Apps