Sub topic 13
Controlling Indexing: noindex versus robots.txt
This chapter covers the two main tools site owners use to influence what ends up in a search index, and why mixing them up is a common source of bugs. It assumes you know basic HTTP status codes, can read HTML, and can follow short Python snippets. It also assumes you have seen the earlier chapters on robots.txt and canonical URLs.
Two different questions
Crawling and indexing are separate stages. Each tool answers a different question about one of them.
- robots.txt answers: "May this crawler fetch this URL?" It controls crawling.
- noindex answers: "May this page appear in the index?" It controls indexing.
A crawler that obeys robots.txt never requests a blocked URL. It therefore never sees the page's HTML, its HTTP headers, or any directive inside them. Search engines can still list a blocked URL, because other pages may link to it. The URL can be indexed without content. It may show up as a bare link with no description.
What each tool can and cannot do
| Goal | robots.txt Disallow | noindex |
|---|---|---|
| Stop the crawler from fetching a URL | Yes | No |
| Keep the page out of search results | Not reliably | Yes, once the page is recrawled |
| Save crawl budget on low-value URLs | Yes | Only partly, since the page is still fetched |
| Work on non-HTML files such as PDFs | Yes | Yes, through an HTTP header |
| Remove a page that is already indexed | No | Yes, after the next crawl |
| Hide secrets from people | No | No |
Neither tool is access control. Both are requests to well-behaved crawlers. Anyone can still open the URL. Protect private content with authentication.
The noindex directive
You can send noindex in two ways. Both carry the same meaning.
As a meta tag
Place this in the <head> of an HTML page:
<meta name="robots" content="noindex, follow">The value noindex tells search engines not to include the page. The value follow says the crawler may still follow the page's links. Following links is the default, so follow is optional. A page that stays noindexed for a long time may eventually have its links ignored, so do not rely on a noindexed page to pass discovery to other URLs.
You can target one crawler by replacing robots with that crawler's name. For example, name="examplebot" applies the rule only to a crawler that identifies with that name. A general robots tag applies to all crawlers that honor it.
As an HTTP header
HTML tags do not work for images, PDFs, or other files. For those, send the X-Robots-Tag response header:
HTTP/1.1 200 OK
Content-Type: application/pdf
X-Robots-Tag: noindexThe header also works for HTML pages. It is useful when you want to apply a rule to many URLs from server configuration instead of editing every template.
Other robots directives
The same two mechanisms accept more values. Support varies by search engine, so check the documentation of each engine you care about.
| Directive | Effect |
|---|---|
| `noindex` | Do not include the page in the index |
| `nofollow` | Do not follow links on this page |
| `none` | Shorthand for `noindex, nofollow` |
| `nosnippet` | Do not show a text snippet in results |
| `noarchive` | Do not offer a cached copy |
Why the combination fails
The most common mistake is adding both a Disallow rule and a noindex tag to the same URL. Look at the order of events.
Here is a concrete case. A site owner wants /drafts/ out of search results. They add this to robots.txt:
User-agent: *
Disallow: /drafts/They also add <meta name="robots" content="noindex"> to each draft page. The meta tag has no effect, because crawlers never fetch those pages. If an external site links to /drafts/post-1.html, the engine may still index that URL using the link text.
The fix is to remove the Disallow rule so the crawler can fetch the pages and read the noindex tag. After the pages drop out of the index, you can add the Disallow rule back if you want to stop the fetching. Many sites leave it open permanently, because the cost of fetching a few pages is small.
Checking what a crawler can see
You can test both layers with Python. The first check uses the standard library robots.txt parser. The second fetches a page and looks for a noindex signal in the header and in the HTML.
import re
from urllib.request import Request, urlopen
from urllib.robotparser import RobotFileParser
AGENT = "ExampleBot"
META_RE = re.compile(
r"<meta[^>]+name=[\"']robots[\"'][^>]*content=[\"']([^\"']*)[\"']",
re.IGNORECASE,
)
def indexing_status(url, robots_url):
rp = RobotFileParser()
rp.set_url(robots_url)
rp.read()
if not rp.can_fetch(AGENT, url):
return "blocked by robots.txt (noindex cannot be seen)"
req = Request(url, headers={"User-Agent": AGENT})
with urlopen(req, timeout=10) as resp:
header = resp.headers.get("X-Robots-Tag", "")
html = resp.read().decode("utf-8", errors="replace")
if "noindex" in header.lower():
return "noindex via X-Robots-Tag"
match = META_RE.search(html)
if match and "noindex" in match.group(1).lower():
return "noindex via meta tag"
return "fetchable and no noindex found"
print(indexing_status("https://example.com/drafts/post-1.html",
"https://example.com/robots.txt"))The regular expression only matches the common attribute order, name before content. A production checker should use an HTML parser, as in the link extraction chapter. The function also ignores redirects and error statuses, which matter in practice.
Interactions with other signals
Canonical URLs
A rel="canonical" link suggests which URL is the preferred version among duplicates. It is a hint. A noindex tag is a directive. Avoid sending conflicting signals, such as pointing a canonical at a noindexed page. The engine may drop both, or pick one unpredictably.
Sitemaps
A sitemap is a list of URLs you want indexed. Listing a noindexed or blocked URL in it contradicts that purpose. Keep sitemaps limited to canonical, indexable pages.
Status codes
A page that returns 404 or 410 is removed from the index after the engine recrawls it and confirms the error. A 410 (gone) is a slightly stronger signal than a 404. For a page that has moved, use a 301 redirect instead of noindex. For a page that must stay live but unlisted, use noindex.
JavaScript-inserted tags
If JavaScript adds or removes the robots meta tag, the engine only sees the change after rendering. Rendering happens later than the first fetch. A page that ships with noindex in raw HTML and tries to remove it with JavaScript may be treated as noindex and never rendered. Put the directive you want in the initial HTML.
Timing
Neither tool acts instantly.
- You add noindex to a page.
- The crawler must schedule a recrawl of that URL.
- It fetches the page and reads the directive.
- The indexing system drops the page.
- Search results stop showing it.
Low-priority pages can wait weeks for the recrawl. Some engines offer a removal tool for urgent cases. Such tools usually hide a URL temporarily, and you still need the permanent signal.
Choosing the right control
- Page should be crawled and indexed: do nothing special, and keep it out of robots.txt blocks and noindex.
- Page should be reachable but not in results: use noindex, and keep it crawlable.
- Crawler wastes requests on endless low-value URLs, such as faceted search or session parameters: use robots.txt
Disallow, accepting that some blocked URLs may still be listed. - File is not HTML: use
X-Robots-Tag. - Content is private: require a login. Do not use either tool.
Exercise
A site blocks /old-offers/ in robots.txt and adds noindex to every page there. Months later, some /old-offers/ URLs still appear in search results with no description. Explain why, and give the fix.
Show answer
The Disallow rule stops the crawler from fetching the pages, so it never reads the noindex tag. Other pages link to the URLs, so the engine can still list them without content. To fix it, remove the Disallow rule so the crawler can fetch the pages and see noindex. Once they drop out of the index, you may restore the block if you want to stop the fetching.
Exercise
You need to keep a set of PDF files out of search results. Which mechanism do you use, and how do you apply it?
Show answer
Use noindex through the X-Robots-Tag HTTP header, because PDFs have no HTML head for a meta tag. Configure the server to send "X-Robots-Tag: noindex" for those files, and make sure robots.txt does not block them.
Exercise
The checker function in this chapter returns "blocked by robots.txt (noindex cannot be seen)" for a URL. Does that result prove the URL is absent from the index?
Show answer
No. It only shows that a compliant crawler cannot fetch the page. The URL can still be indexed from external links, without content.