Sub topic 1
Crawling vs. indexing: what each file controls
Prerequisites
This chapter assumes you can read a URL and know what an HTTP status code is, such as 200 or 404. You should also know that a website is a set of pages arranged in directories. Later chapters use XML and a little Python, but this one needs neither.
Three separate stages
A search engine handles a page in stages, and each stage is a separate decision:
- Crawling is requesting a URL and downloading what the server returns. The program that does this is a crawler (also called a bot or spider).
- Indexing is analyzing the downloaded content and deciding whether to store it in the search engine's database, the index.
- Ranking is choosing which indexed pages to show for a given search, and in what order.
A URL can pass one stage and fail the next. A page can be crawled but not indexed, because it is a duplicate or has a noindex instruction. A page can also be indexed without ever being crawled, which surprises many people and is covered below.
What each file controls
Both files are plain text served from your site, but they act at different points.
| File | Main job | Stage it affects | Strength |
|---|---|---|---|
| robots.txt | Tells crawlers which URLs they may request | Crawling | Rules that well-behaved crawlers follow |
| XML sitemap | Lists URLs you want discovered, with optional last-modified dates | Discovery | A hint, not a command |
Neither file guarantees that a page will be indexed or ranked. robots.txt can only say "do not fetch this." A sitemap can only say "these URLs exist and matter to me." The search engine still decides what to keep.
Why the distinction matters
Suppose you want a page to stay out of search results. A common first move is to add a Disallow rule to robots.txt. That stops the crawler from fetching the page. It does not remove the URL from the index.
If other sites link to the blocked URL, the search engine may still index the bare address. It can show it with no description, because it was never allowed to read the page. Worse, the crawler cannot see a noindex instruction on a page it is forbidden to fetch, so blocking can prevent the very signal you wanted it to read.
The reverse mistake is also common. Listing a URL in a sitemap does not force indexing, and a sitemap URL that is blocked by robots.txt sends a contradictory message. You should keep both files consistent with each other.
A quick decision guide
- To save server load or keep crawlers out of low-value areas such as internal search results, use robots.txt.
- To help crawlers find new or deep pages, use a sitemap.
- To keep a page out of search results, use
noindex, and leave the page crawlable. - To protect private data, use authentication. robots.txt is not access control.
The rest of this tutorial builds on this split. First you will write robots.txt rules, then sitemaps, and finally you will test both.
Exercise
A page at /old-offer/ still shows up in search results with no description, even though you added "Disallow: /old-offer/" to robots.txt. Which stage did the rule affect, and why does the URL still appear?
Show answer
The rule affected crawling only. The crawler no longer fetches the page, but the URL can still be indexed from links pointing to it, so it appears without a description. Removing the Disallow rule and serving a noindex instruction lets the crawler read the page and drop it from the index.