All articles 9 min read 8 sections Code examples

robots.txt and noindex: how to keep a page out of search

The robots.txt file is a plain text file in UTF-8 encoding. It sits in the root of your domain (https://mypersonaldomen.com/robots.txt) and must be no larger than 500 KB. In it you tell search engine crawlers — Google, Bing and others — which parts of your site they should not visit.

The key thing to understand from the start: robots.txt controls crawling, not indexing. It asks a crawler not to download a page. But if anything links to that page, from your own site or from somewhere else, the URL can still show up in search results — with no description, carrying a note along the lines of "No information is available for this page". To keep a page out of search for certain, you need the noindex meta tag, which is a different tool entirely.

Below you will find both: robots.txt syntax with examples, the robots meta tag and all of its values, the X-Robots-Tag HTTP header for files, and how to verify that any of it actually worked.

robots.txt or noindex: which one to use

It depends on the problem you are solving:

  • The page must not appear in search → the noindex meta tag. The page has to stay open to crawling, otherwise the crawler will never see the tag.
  • You need to save crawl budget — for example, your site generates tens of thousands of near-identical filter and sorting pages → Disallow in robots.txt.
  • What you need to block is not an HTML page but a PDF, an image, a video or an archive → the X-Robots-Tag HTTP header.
  • You need to hide something from people → none of the three will do it. robots.txt is public, anyone can open it, and a list of disallowed directories often reads as a map of where the interesting things are. Use a password or server-level access control.

The most common mistake is blocking a page in robots.txt and expecting it to drop out of the index. That is not how it works, and here is why.

Why a page blocked in robots.txt still shows up in search

If you have ever seen the status "Indexed, though blocked by robots.txt" in Google Search Console, this is exactly that case.

The logic is simple. Disallow stops the crawler from downloading the page. But Google learns that the page exists from links — internal, external, or from your sitemap. The URL is known, the content is not available, so the search engine lists the page without a description.

There is a second side to the same problem. If a page is blocked in robots.txt, the crawler cannot read the noindex meta tag on it either. You end up in a loop: the tag is there, but nobody ever sees it.

So when a page is already in the index, the right sequence is:

  • remove the Disallow rule for that page;
  • add <meta name="robots" content="noindex"> to its <head>;
  • wait for the crawler to visit and see the tag — usually a few days to two weeks;
  • once the page has dropped out of the index you may block it in robots.txt again, although by that point there is rarely any reason to.

If a page has to disappear from search urgently, Search Console has a Removals tool: it hides the URL for roughly six months, which is more than enough time for noindex to do its job.

robots.txt syntax

User-agent: the name of the crawler you are addressing. * means every crawler.

Disallow: the path the crawler should not download.

Allow: an exception to a block. Useful when something inside a disallowed directory needs to stay open.

Sitemap: the full URL of your sitemap, including https://. This directive is not tied to any User-agent block — it can go anywhere in the file.

Crawl-delay: a pause between crawler requests. The directive is obsolete: Google does not support it, and Yandex stopped honouring it in 2018. Crawl rate is set in the webmaster panels themselves. Bing still takes the directive into account.

Host: an obsolete Yandex directive that used to declare the primary mirror of a site. It was dropped in 2018 — the primary version is now set with a 301 redirect and a canonical URL.

Worth knowing:

  • # starts a comment — everything after it on the line is ignored;
  • paths are case sensitive: /Tmp/ and /tmp/ are different URLs;
  • * matches any sequence of characters, $ marks the end of a URL;
  • a blank line separates blocks, so there must be no blank lines inside a single User-agent block;
  • if a crawler has a block of its own, it ignores the general User-agent: * block completely — every rule you still want has to be repeated in its block;
  • when Allow and Disallow conflict, Google follows the more specific (longer) rule;
  • robots.txt applies only within its own protocol, domain and port: a file on https://site.com governs neither http://site.com nor sub.site.com — a subdomain needs its own file.

robots.txt examples

Block the whole site — useful while the site is still in development:

User-agent: *
Disallow: /

Open the whole site:

User-agent: *
Disallow:

Stop Google from crawling the /tmp/ directory:

User-agent: Googlebot
Disallow: /tmp/

Stop Google from crawling one specific file:

User-agent: Googlebot
Disallow: /tmp/provider.html

Block a whole directory but keep one file inside it open:

User-agent: *
Disallow: /tmp/
Allow: /tmp/provider.html

Block every .pdf file for every crawler:

User-agent: *
Disallow: /*.pdf$

Block internal search results and URLs with sorting parameters:

User-agent: *
Disallow: /search
Disallow: /*?sort=
Disallow: /*?utm_

Different rules for different crawlers, plus a sitemap:

User-agent: *
Disallow: /admin/
Disallow: /cart/
User-agent: Bingbot
Disallow: /admin/
Disallow: /cart/
Disallow: /compare/
Sitemap: https://mypersonaldomen.com/sitemap.xml

Note the last example: Bingbot has a block of its own, so the shared rules had to be repeated inside it — otherwise it would only have read /compare/.

The robots meta tag: every value

The meta tag goes in the <head> of a page and, unlike robots.txt, it is not a suggestion — it is a direct instruction about what to do with that page.

<meta name="robots" content="noindex"> — keep the page out of search results. The crawler still follows links on it.

<meta name="robots" content="noindex, nofollow"> — keep the page out of search results and do not follow its links. The same thing can be written as content="none".

<meta name="robots" content="nofollow"> — index the page, but do not follow the links on it.

<meta name="robots" content="noarchive"> — do not store a cached copy of the page.

<meta name="robots" content="nosnippet"> — show only the title in search results, with no text description.

<meta name="robots" content="max-snippet:160, max-image-preview:large"> — limit the length of the description and the size of the image shown in results.

<meta name="robots" content="unavailable_after: 2027-01-01T00:00:00+03:00"> — drop the page from search after a given date. Handy for promotions and events with a known end date.

The default is index, follow, and there is no need to write it out: without any tag, a page is indexed anyway.

You can address the tag to one specific crawler: <meta name="googlebot" content="noindex"> for Google, <meta name="bingbot" content="noindex"> for Bing. If both a general robots tag and a crawler-specific one are present, the crawler follows the one addressed to it.

The key condition, once more: the page must be open to crawling. A meta tag on a page blocked in robots.txt does nothing, because nothing ever reads it.

One more thing: a Noindex: line inside robots.txt itself does not work. Google officially stopped honouring it on 1 September 2019. If you come across one in somebody else's file, it is a leftover from old advice.

X-Robots-Tag: how to block PDFs, images and other files

A meta tag can only live in HTML. For PDFs, images, video and archives you use the X-Robots-Tag HTTP header — it accepts the same values, but the server sends it.

Apache, in .htaccess:

<FilesMatch "\.pdf$">
Header set X-Robots-Tag "noindex, nofollow"
</FilesMatch>

Nginx, in the site configuration:

location ~* \.pdf$ {
    add_header X-Robots-Tag "noindex, nofollow";
}

One command is enough to check that the header is actually being sent:

curl -I https://mypersonaldomen.com/file.pdf

The response should include the line X-Robots-Tag: noindex, nofollow among its headers.

Editing server configuration requires access to the server: on a dedicated server you have it in full, while shared hosting usually leaves you only .htaccess. You can connect and edit the config over SSH — the commands you will need are collected in our SSH command reference.

How to check that it worked

  • open https://your-domain/robots.txt in a browser — the file should return a 200 status and read as plain text;
  • Search Console → Settings → the robots.txt report: when Google last fetched the file, what it received, and whether it found errors;
  • Search Console → URL Inspection: paste a page URL and check whether crawling and indexing are allowed — it also shows which tag the crawler found;
  • Search Console → Page indexing: look for "Indexed, though blocked by robots.txt" and "Excluded by 'noindex' tag" — that is your list of what has worked and what has been set up wrong;
  • for files, use curl -I as shown above.

Changes do not take effect instantly. Google refetches robots.txt roughly once a day, and to see a new meta tag the crawler has to visit the page itself — anything from a couple of days to several weeks, depending on how often it comes by.

Common mistakes

  • Blocking a page in robots.txt to get it out of search. You need noindex, and the page has to stay crawlable.
  • Setting noindex and Disallow at the same time. The crawler never reads the tag and the page stays in the index.
  • Forgetting to remove Disallow: / after launch. A classic: the site is live and missing from search for months.
  • Blocking CSS and JS. Google renders pages like a browser. Without styles and scripts it sees something different from what your visitors see, and may decide the page is unusable on mobile.
  • Treating robots.txt as security. The file is public, and a list of disallowed directories reads as a map.
  • Mismatched case in paths. Disallow: /Admin/ will not block /admin/.
  • Putting noindex on pagination pages. Products on page two and beyond then fall out of crawling entirely. Pagination is handled with canonical URLs and internal links, not noindex.

What is usually worth blocking — and what is not

Worth blocking:

  • login, registration and password reset pages, and the client area;
  • the cart and checkout;
  • internal site search results;
  • URLs with UTM tags and sorting parameters — though a canonical URL is a better answer here than a block;
  • technical directories: /cgi-bin/, temporary folders, the admin panel;
  • test and staging copies of the site — but those are better protected with a password than with robots.txt.

Not worth blocking: CSS and JS files, fonts, and any images that are part of how your pages look. A search engine needs all of it to see your site the way a person does.