Sub topic 2
Reading status codes: 200, 301, 404, 410, 500
This chapter assumes you can run curl in a terminal, know what an HTTP request and response are, and have seen an nginx or Apache access log. It covers how to read a status code and what a crawler does with each one. Later chapters cover redirects and fixes in detail.
What a status code is
Every HTTP response starts with a status line, such as HTTP/1.1 404 Not Found. The three-digit code is the part software acts on. The text after it is only a label. The first digit gives the class:
| Class | Meaning | What it tells a link checker |
|---|---|---|
| 2xx | Success | The server returned what was asked for |
| 3xx | Redirection | The content is elsewhere. Follow the `Location` header |
| 4xx | Client error | The request cannot be satisfied as sent. This usually means a broken link |
| 5xx | Server error | The server failed on a request that may be valid |
Classify by the first digit when you meet a code you don't know. A 4xx means the problem is with the request or the URL. A 5xx means the problem is on the server.
The codes you will see most
200 OK
The server returned the content. A 200 means the server answered successfully, not that the page is useful. A page that says "Sorry, nothing here" but returns 200 is a soft 404, covered in a later chapter. The server's claim and the page's content can disagree, so check both.
301 Moved Permanently
The URL has a new permanent address, given in the Location header. Clients and search engines should update their records to the new URL. A 301 is not an error, but each one adds a request. Chains of them are a problem, which the redirect chapters cover.
404 Not Found
The server has no resource at this URL and gives no information about whether it ever did. It is the default "broken link" code. It is also the correct response for URLs that never existed, such as mistyped ones. A site with a few 404s is normal. A 404 on a URL that other pages link to is a defect.
410 Gone
The resource existed and was removed on purpose, with no replacement. Use it when you retire content deliberately. Google has said it treats 410 much like 404 in practice, though a 410 may be dropped from the index slightly faster. Other tools and some crawlers also read 410 as a clearer statement of intent.
500 Internal Server Error and its relatives
A 5xx means the server failed. The common ones are:
- 500: an unhandled error, often a bug or a broken configuration.
- 502 Bad Gateway: a proxy such as nginx got an invalid answer from the application behind it.
- 503 Service Unavailable: the server is overloaded or down for maintenance. A
Retry-Afterheader can say when to return. - 504 Gateway Timeout: the proxy gave up waiting for the application.
A 5xx on a URL does not mean the link is broken. It means the server could not respond at that moment. Recheck before you act on it.
Other codes that cause confusion
| Code | Meaning | How to treat it in a link audit |
|---|---|---|
| 302, 307 | Temporary redirect | Not an error. Check whether it should be permanent |
| 304 | Not Modified | Appears only on conditional requests. Not an error |
| 401 | Authentication required | The page needs a login. Search engines cannot index it |
| 403 | Forbidden | The server refused the request. This can be a bot block, not a missing page |
| 429 | Too Many Requests | You are being rate limited. Slow your checker down |
A checker that reports every 403 as a broken link will flag many working pages. Some sites return 403 to automated user agents or to unusual request patterns. Test a 403 in a browser before you call it broken.
Reading codes with curl
Print only the status code of a URL:
curl -s -o /dev/null -w '%{http_code}\n' https://example.com/old-page-s silences the progress meter, -o /dev/null discards the body, and -w prints a chosen variable after the transfer. By default curl does not follow redirects, so a moved page prints 301 rather than the final status.
Check a list of URLs, one per line, with a 10 second limit per request:
while read -r url; do
code=$(curl -s -m 10 -o /dev/null -w '%{http_code}' "$url")
echo "$code $url"
done < urls.txtThe code 000 is not an HTTP status. It means curl got no response at all, for example because of a DNS failure, a refused connection, or a timeout. Treat 000 as a separate category in your report.
Reading codes in server logs
In the common and combined log formats, field 9 is the status code. Count how often each code appears:
awk '{print $9}' /var/log/nginx/access.log | sort | uniq -c | sort -rnThen list the 20 most requested paths that returned 404:
awk '$9 == 404 {print $7}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -20The second command shows broken URLs weighted by real demand, which helps you decide what to fix first.
How crawlers act on each code
The details behave as follows:
- 2xx: the page is eligible for indexing, subject to its content and directives.
- 301 and 308: the crawler follows the redirect and treats the target as the preferred URL. Googlebot follows a limited number of hops, about 10, before giving up.
- 404 and 410: the URL is removed from the index after the crawler has seen the error, usually over days or weeks. Crawlers recheck these URLs for a while, so errors do not disappear at once.
- 5xx: the crawler retries later. If errors continue, it reduces its crawl rate. If they persist for a long time, URLs can be dropped from the index.
Common mistakes
- Trusting the page text over the status code. A friendly "page not found" message with a 200 status is a soft 404.
- Treating 5xx like 404. Deleting or redirecting a URL because it returned 500 once removes a page that may be fine.
- Redirecting every 404 to the home page. This hides real errors and tends to be treated as a soft 404.
- Checking with HEAD only. Some servers answer HEAD and GET differently. Confirm odd results with a GET request.
- Ignoring
000. DNS failures and timeouts are real link problems, but they come from outside HTTP.
Exercise
A link checker reports 403 for 40 external links, and every one loads in your browser. What is the likely cause, and what should you do before removing the links?
Show answer
The remote servers are probably blocking automated requests by user agent or request rate, so the 403 reflects the checker rather than a missing page. Retry a few of them with a browser-like user agent and a slower rate. If they still return 403 and load in a browser, mark them as "blocked to bots" and do not remove them.
Exercise
Your access log shows many requests for /blog/2019-sale returning 404. The sale ended and nothing replaces it. Which status code is the most accurate, and why?
Show answer
410 Gone. The page existed and was removed on purpose with no replacement, so 410 states that intent. A 404 is also acceptable and search engines treat the two similarly, but 410 is more precise.