Sub topic 1
How a Browser and Crawler Request a URL
This chapter explains what happens between typing a URL and getting a response. Later chapters on status codes, redirects, and crawling depend on this model. It also shows the first curl commands you will use throughout the tutorial.
Prerequisites
This chapter assumes you can do the following:
- Read a URL and name its parts (scheme, host, path, query).
- Run commands in a terminal and read their output.
- Read basic HTML, including
<a href="...">links. - Recognize nginx or Apache, or know that your CMS runs on a web server.
You do not need to know status codes or redirects yet. The next chapters cover them.
From URL to response
A URL such as https://example.com/blog/post?id=7 has these parts:
| Part | Example | Role |
|---|---|---|
| Scheme | `https` | Protocol and whether the connection is encrypted |
| Host | `example.com` | Which server to contact |
| Path | `/blog/post` | Which resource on that server |
| Query | `?id=7` | Extra parameters for the resource |
| Fragment | `#section` | Position inside the page, handled by the browser only |
The fragment is never sent to the server. A link to /page#top and a link to /page make the same request. A checker that tests URLs should strip fragments before comparing or requesting them.
A client (a browser or a crawler) goes through these steps:
- Look up the host name in DNS to get an IP address.
- Open a TCP connection to that address, usually on port 443 for HTTPS.
- For HTTPS, run a TLS handshake to encrypt the connection and check the server's certificate.
- Send an HTTP request.
- Read the HTTP response: a status line, headers, and usually a body.
Failures in the first three steps happen before any HTTP status exists. A dead domain, a server that is down, or an expired certificate gives the client no status code at all. Tools report these as errors such as "could not resolve host" or "certificate has expired". When you audit links, treat these as a separate category from 404s.
What a request looks like
An HTTP request is plain text. A minimal one looks like this:
GET /blog/post?id=7 HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0
Accept: text/htmlThe first line holds the method, the path with query, and the protocol version. The Host header tells the server which site you want, which lets one server host many sites on one IP address. The User-Agent header identifies the client.
A response has a similar shape:
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 5120
<!doctype html>
...The first line is the status line. It holds the protocol version, a three-digit status code, and a short reason phrase. Headers follow, then a blank line, then the body. HTTP/2 and HTTP/3 carry the same information in a binary format, but the concepts are identical. Tools like curl still show you the same status code and headers.
Methods that matter for link checking
| Method | What it does | Use in link checking |
|---|---|---|
| `GET` | Requests the full resource | What browsers and crawlers use for pages |
| `HEAD` | Same as GET, but the server returns headers only | Fast status checks without downloading the body |
| `POST` | Submits data | Not used for link checks |
HEAD is cheaper than GET, but some servers handle it badly. A few return 405 (method not allowed) or a different status than GET would return. If a HEAD check reports an error, confirm it with GET before you call the link broken.
Browser versus crawler
Both send requests like those above. Their behavior differs in ways that matter for debugging.
| Aspect | Browser | Search engine crawler |
|---|---|---|
| Starting point | A URL the user types or clicks | A queue of known URLs from links, sitemaps, and past crawls |
| Redirects | Follows them, up to a limit, and shows the final page | Follows a limited number of hops, then may stop and retry later |
| JavaScript | Runs it | May render it later, in a separate step |
| Identity | Browser `User-Agent` | Declares itself, for example `Googlebot` |
| Rate | One page at a time per user | Throttled by the crawler to avoid overloading the server |
| Memory | Cache and history | Stores status codes and revisits URLs on its own schedule |
Two consequences follow:
- A page that works in your browser can fail for a crawler. Causes include a firewall rule that blocks bots, a rule keyed on
User-Agent, or content that only appears after login. - A crawler does not see "the page you meant". It sees the exact status code and headers the server sent for that URL. A page that looks fine can still return an error code to the crawler.
Crawlers also read robots.txt before fetching. A URL blocked there is not requested, so it produces no status code in your logs. Do not confuse "blocked from crawling" with "broken".
Making the request yourself with curl
curl lets you see the same status line and headers a crawler sees. This is the fastest way to answer "what does the server actually return for this URL?"
curl -sI https://example.com/old-pageThe flags mean:
-shides the progress meter.-Isends aHEADrequest and prints only the headers.
Typical output:
HTTP/2 301
location: https://example.com/new-page
content-type: text/htmlThe status is 301 and the location header gives the next URL. The client must make a new request to that URL. This is the basic mechanism of every redirect, and the next chapters build on it.
To follow redirects and print only the status line and Location header of each hop, use this command from the tutorial's toolkit:
curl -sIL https://example.com/old-page | grep -iE '^(HTTP|location)'-L tells curl to follow redirects. The grep -iE filter keeps only the lines that start with HTTP or location, ignoring case, because HTTP/2 sends header names in lowercase.
To summarize the whole trip in one line, use curl's write-out variables:
curl -sL -o /dev/null -w '%{num_redirects} redirects, final status %{http_code}, final URL %{url_effective}\n' https://example.com/old-pageHere -o /dev/null discards the body, and -w prints a template after the transfer finishes. %{num_redirects}, %{http_code}, and %{url_effective} are filled in with the number of hops, the last status code, and the last URL.
Pretending to be a crawler
You can test whether your server treats bots differently by changing the User-Agent:
curl -sI -A 'Googlebot/2.1 (+http://www.google.com/bot.html)' https://example.com/pageCompare the result with a plain curl -sI. If the status codes differ, something on your server or in front of it (a CDN, a firewall, a plugin) treats the two clients differently. This only shows what the server returns to that header. Real Googlebot is verified by IP address, so a firewall may still treat the real crawler differently from your test.
Common errors when checking URLs
- Testing only the final page. A browser hides redirects. Always check the status of the URL as linked, not just where it ends up.
- Ignoring the scheme and host.
http://example.com/page,https://example.com/page, andhttps://www.example.com/pageare three different URLs. Each can return a different response. - Trusting the browser address bar. After a redirect, the bar shows the final URL, not the one you requested.
- Forgetting that a trailing slash can matter.
/pageand/page/are different paths to the server, and many servers redirect between them. - Reading a
HEADresult as final. Confirm any surprisingHEADresult withGET. - Caching confusion. Browsers cache some redirects, especially permanent ones. Test with curl or a private window to avoid stale results.
Summary of the model
Every URL check is a short exchange. The client resolves a host, connects, sends a method and a path, and reads a status code, headers, and a body. Failures before the HTTP step have no status code. After it, the status code tells the client what to do next: accept the content, follow a Location header, or treat the URL as an error. The next chapter covers what each status code means.
Exercise
You run curl -sI https://example.com/page and get HTTP/2 200, but a colleague says Googlebot reports an error for the same URL. Name two possible causes and one curl command that helps you test the first.
Show answer
Possible causes: a firewall or CDN rule that blocks or treats bots differently based on User-Agent or IP address, and a cached error at a CDN or proxy that your request did not hit. To test the first, send the request with a crawler User-Agent and compare it with the plain request: curl -sI -A 'Googlebot/2.1 (+http://www.google.com/bot.html)' https://example.com/page. If the status codes differ, the server treats the two clients differently.
Exercise
Why can http://example.com/page, https://example.com/page, and https://www.example.com/page return three different results, and which part of the request or connection differs between them?
Show answer
They are three different URLs. The scheme decides whether the request uses an encrypted connection on port 443 or plain HTTP on port 80, and the host decides which DNS name is resolved and which site the server serves through the Host header. Each combination can have its own server configuration, redirect rules, or certificate, so each must be checked on its own.