Sub topic 2
Reading status codes: 200, 301, 404, 410, 500
This chapter assumes you know what a URL is, can run commands in a terminal, and have seen an HTML anchor tag. It covers the five status codes you will meet most often when auditing links.
What a status code tells you
Every HTTP response starts with a status line, such as HTTP/1.1 404 Not Found. The three-digit code is the server's verdict on the request. The first digit gives the class:
| Class | Meaning | Typical use |
|---|---|---|
| 2xx | Success | The page was delivered |
| 3xx | Redirection | Look somewhere else |
| 4xx | Client error | The request cannot be satisfied as sent |
| 5xx | Server error | The server failed on a valid request |
Crawlers and browsers act on the code, not on what the page looks like. A page that reads "Sorry, not found" but sends 200 is treated as a working page. Chapter 6 covers that case.
The five codes
- 200 OK. The content is in the response body. This is the only code that means "index this page" without further steps.
- 301 Moved Permanently. The
Locationheader holds the new URL. Clients should update their records and pass the old URL's signals to the new one. - 404 Not Found. The server has no page at this URL, and it makes no promise about whether that is permanent.
- 410 Gone. The page existed and was removed on purpose. It will not return. Search engines tend to drop a 410 URL slightly faster than a 404.
- 500 Internal Server Error. The server crashed or misconfigured itself while handling the request. The URL may be perfectly valid.
Seeing the codes yourself
Use curl -I, which sends a HEAD request and prints only the headers.
curl -sI https://example.com/old-page | head -n 5A moved page might return:
HTTP/2 301
location: https://example.com/new-page
content-type: text/htmlTo print only the code for a list of URLs, use curl's write-out variable:
for u in https://example.com/ https://example.com/old-page https://example.com/gone; do
curl -s -o /dev/null -w '%{http_code} %{url_effective}\n' "$u"
doneHere -o /dev/null discards the body, and %{http_code} is the status of the response. Without -L, curl does not follow redirects, so a 301 is reported as 301.
Common mistakes
- Reading a 200 as healthy without checking the content. An error page served with 200 is a soft 404.
- Using 404 for content you removed on purpose. Use 410 when you are certain it is gone.
- Using 301 for a temporary move. Clients may cache a 301 for a long time, so undoing it is slow.
Exercise
You run curl -s -o /dev/null -w '%{http_code}' https://example.com/pricing-2019 and it prints 410. What does the server mean, and what should you do with internal links that point to this URL?
Show answer
The server is saying the page existed, was removed deliberately, and will not come back. Update or remove internal links to it, or point them to a relevant replacement page, because a 410 gives visitors and crawlers a dead end.