Zubair Akhtar logo — Muhammad Zubair Akhtar, Software Engineer

Blog

Robots.txt for SEO: What to Block, and Why It Won't Deindex a Page

Robots txt controls crawling, not indexing. What a robots txt file should block, and why Disallow will not deindex a page.

Muhammad Zubair Akhtar

A robots txt file is a crawl hint. It tells cooperating crawlers which URLs they may fetch on that host. It does not remove a URL from Google, and a Disallow rule will not deindex a page you want gone. I still open inherited sites and find the opposite setup: the URL someone wants dropped is blocked in robots.txt, a noindex tag sits on a response the bot will never request, and the listing stays up as a bare link.

I am Zubair Akhtar, a senior software engineer in Lahore, Pakistan. I work on Laravel, WordPress, and Next.js, and the crawl file is part of the first pass I run before anyone talks about content. That wider pass is the technical SEO checklist. This page is only the robots.txt file: which lines matter, what a robots txt file should block, and which signals actually take a URL out of the index. A search for robots txt no index usually means someone wants one file to do both jobs. Google does not honor a noindex line inside robots.txt.

If you want the live file, the status codes, and the index rules checked on a property, that work sits under technical SEO services. I am not attaching a fresh crawl export here. The rules below are the ones Google documents for robots.txt and for noindex.

Decision diagram for robots.txt: allow crawl to index a page, or allow crawl then noindex or 410 to remove it

Figure 1. Both outcomes start by allowing the fetch. Indexing needs a 200. Removal needs noindex or a 410. Disallow is the wrong tool for a URL you want gone.

What a robots txt file actually does

Crawl and index are different jobs. Crawl is the fetch: Googlebot requests the URL and reads the status, the headers, and the HTML. Index is the stored result. Google can keep a URL it already knows, including a URL it is no longer fetching.

robots.txt sits in front of the fetch. Googlebot downloads it from the root of the host before it crawls. Google's introduction describes the file as a way to manage which URLs a crawler may access, so a server is not flooded with requests that do not matter, and it says the file is not how you keep a page out of Google. A disallowed URL can still be indexed from other links, often as an address with no snippet, because the content was never fetched. The disallow also hides any removal signal on the response.

The file is public, and only cooperating crawlers have to follow it. Google's specification leaves some safety crawlers outside these rules. Private data needs a login.

The file that counts sits at the host root, such as https://example.com/robots.txt. A copy in a subfolder is ignored. Rules apply to that host, protocol, and port, so www and the apex are separate, and http does not govern https. Paths are case-sensitive.

Google ignores unsupported lines and anything past the 500 KiB limit. A dump of spam URLs fails twice: the tail may be dropped, and each listed path is one Google will stop fetching. Google caches the file, generally for up to a day, and longer if it cannot refresh it.

Directives worth putting in the file

Google's robots.txt specification supports four fields: User-agent, Allow, Disallow, and Sitemap. I use those.

User-agent

A group starts with User-agent. User-agent: applies when no more specific group matches. Google uses that one group and does not merge it with . A Googlebot block that only says Allow: / drops an admin Disallow written under *. Repeat every rule you still want, or skip the specific group.

Groups for the same crawler are combined. Line order does not pick the winner. A Sitemap line is not a group boundary, and a sitemap line between two User-agent lines can glue the groups together, so a Disallow: / lands on a bot you meant to allow. Put every Sitemap line after the groups.

Disallow and Allow

Disallow is a path prefix the crawler should not fetch. Disallow: /admin matches /admin, /admin/orders, and /administrator. Disallow: / matches the whole host. An empty Disallow: is ignored. The line that blocks the site is Disallow: /.

Allow reopens a path under a broader disallow. The WordPress case I keep is disallow /wp-admin/ and allow /wp-admin/admin-ajax.php, because public pages call that endpoint.

Google supports * for any run of characters and $ for the end of the path. It picks the longest matching path. When two matches conflict, it uses the least restrictive rule. Allow: / beside Disallow: / leaves the host crawlable. A staging block is Disallow: / with no equally specific allow next to it. The last line does not win.

Sitemap

Sitemap takes an absolute URL, protocol and host included. Google does not guess www versus apex, or http versus https. You can list more than one. The line helps discovery. It does not force indexing, override noindex, or cancel a 410. Check the live file so the value is not still http://localhost/sitemap.xml.

Crawl-delay

Crawl-delay is not a supported Google field. Google ignores it, the same way it ignores a Noindex line in this file. If the origin is struggling, the useful work is fewer junk URLs and a cheaper response. A directive Google skips will not slow Googlebot down.

There is no supported robots txt no index directive. Google's page on blocking indexing says to put noindex in a robots meta tag or an X-Robots-Tag header. The crawler has to be allowed to fetch the URL, or it never sees that tag.

What a robots.txt file should block

Block a path when you do not want it fetched, and you are not trying to erase it from the index with a status code or a noindex tag.

On production I disallow signed-in areas such as /admin, WordPress /wp-admin/ with admin-ajax.php allowed, and internal search when the only goal is fewer fetches. I also disallow a duplicate proxy when Google should store the real file. This site disallows /_next/image and leaves /images/ allowed. That line is this stack, not a WordPress default.

Leave CSS, JavaScript, and images crawlable when the template needs them to render. A disallow on /build/ or /wp-content/themes/ is a rendering bug. Leave every URL you want stored. Leave faceted URLs your templates link to, such as ?sort=, and send noindex if they should not be results. The technical SEO checklist makes that same call. Leave spam, hacked, and retired URLs crawlable too. A disallow there is the next section.

Staging is a different host. Disallow: / can live there if the host is public, together with a login or noindex. Production must not inherit that file. Google then stops fetching a site you can still open in a browser.

A pattern to adapt to paths you actually have:

User-agent: *
Allow: /
Disallow: /admin
Disallow: /search

Sitemap: https://example.com/sitemap.xml

/admin and /search are longer than /, so those prefixes stay blocked.

Goalrobots.txtWhat changes the index
Keep the page in GoogleAllow the URL200, one canonical, a sitemap entry if it should be discovered
Fetch an endless URL space less oftenDisallow the prefix, only if you do not need the URL removedA linked URL may still appear without a snippet
Drop a URL that should not existAllow the URL410 Gone, or 404, seen only if Google fetches
Keep a real URL out of the indexAllow the URLnoindex in a meta tag or X-Robots-Tag
Hide a private toolOptionalAuthentication. Unsigned clients get no content

Why Disallow will not deindex a page

Googlebot does not fetch a URL that robots.txt disallows. The removal signals live on that fetch:

  • A robots meta tag, <meta name="robots" content="noindex">, is in the HTML.
  • An X-Robots-Tag: noindex header is on the response.
  • A 410 Gone or a 404 is the status of the response.

If the crawler never requests the URL, it never sees any of those. Google's noindex documentation says the rule works only when the page is not blocked, so a linked URL can still appear. The robots.txt specification adds that Google may list that URL without a snippet, without having the content. Blocking the URL and also sending noindex cancels the noindex. I will not tell you to Disallow a URL you want removed.

Flow showing a robots.txt Disallow stops the fetch, so Google never sees noindex or a 410 on that URL

Figure 2. Disallow stops the request. The noindex tag and the 410 sit on a response Google does not read, so the URL can remain in the index.

The same trap shows up after a hack. Spam URLs are already indexed. A Disallow on those paths, or a long list of junk URLs in the file, stops the recrawl, so Google never sees the 410 the server started returning. On this site I did the opposite. Unknown URLs stay crawlable, and the response is 410 Gone plus X-Robots-Tag: noindex. How the Search Console removals fit that cleanup is in how I removed hacked spam URLs from Google.

URL Inspection saying the fetch was denied is not a finished removal. The stored URL can still be the listing.

How to remove a URL from Google

Match the tool to why the URL should go, and leave the fetch allowed.

The URL should not exist. Spam, a hacked slug, a deleted product, a tracking query that duplicated a real page. Return 410 Gone. A 404 also means it is missing. Google's notes on unsupported robots rules list both as signals that drop a URL once it is crawled. I use 410 for permanently gone, which is what this site sends for unknown paths, and that response can also send X-Robots-Tag: noindex. Delete any Disallow first.

The URL should stay up for people and stay out of the index. A thin archive, a thank-you page, internal search your templates link to. Keep the 200, add noindex, take it out of the sitemap, and do not disallow it. Google has to recrawl before the tag counts, and a low-importance URL can wait a long time for that visit.

You need the listing hidden while that recrawl happens. Search Console's removals tool is temporary and it expires. It does not replace the 410 or the noindex. The hacked-URL write-up uses it as a bridge. The next fetch is the lasting signal.

The order I follow:

  1. Remove the Disallow that covers the URL, if one exists, and deploy it. The cached robots.txt means this is not instant.
  2. Serve the lasting signal: 410 when the URL should not exist, noindex when humans should still open it.
  3. Drop the URL from the sitemap.
  4. If it is already in results, submit a Search Console removal for the waiting period.
  5. Inspect the URL after Google has fetched again. "Blocked by robots.txt" means the removal signal is still unread.

Private content is the exception: require a login, and do not disallow that wall if you need Google to observe it. A crawler that cannot fetch the wall never records it.

A robots.txt file is not access control

The file is a request to cooperating crawlers. It is not a firewall.

Anyone can request a disallowed path. The server answers unless the application refuses them, and listing /secret-export/ in the file publishes the path. A 401 or 403 on /robots.txt itself does not lock the host. Google treats 4xx on that file, other than 429, as "there is no robots.txt," so there are no crawl restrictions. A 5xx can stall crawling while Google retries. Serve a normal 200 text file.

noindex is for a page you will hand to a crawler and still want kept out of results. A session check is for a page you will not hand over. Customer data and admin actions need that check on the response.

Check the live file after you edit it

I open /robots.txt on the public host after every deploy that touches it. On Laravel, a static public/robots.txt wins over a route of the same path, which is an easy way to ship a file you thought the app was generating. The route I use when the body should come from config is already in the technical SEO checklist.

  1. Production is not serving a staging Disallow: /.
  2. CSS and JavaScript used by indexable templates are allowed. Compare the paths in the HTML with the prefixes in the file.
  3. The Sitemap line is the production sitemap, and that URL returns 200.
  4. No Disallow covers a URL you are dropping with noindex or 410. Request one and read the status and the X-Robots-Tag header, then confirm in Search Console after Google has refreshed the file and fetched again.

FAQ

Will Disallow remove a page from Google?

No. Disallow asks Googlebot not to fetch the URL. Google can keep the URL in results without a snippet, especially when other pages link to it. To drop it, allow the fetch and return noindex or a 410.

Can I noindex a URL from robots.txt?

Not with any directive Google supports. A Noindex line in the file is ignored. Put noindex in a meta tag or an X-Robots-Tag header, leave the URL crawlable, and keep it out of the sitemap if it should not be stored.

What should a robots.txt file block?

Block paths you do not want crawled and are not trying to erase: admin screens, and generators such as internal search when you only need fewer fetches. Leave CSS and JavaScript crawlable on pages you want rendered. Leave URLs you want removed crawlable, so Google can read noindex or a 410.

Does Google honor Crawl-delay?

No. The robots.txt specification does not support Crawl-delay, and unsupported fields are ignored. Cut crawl pressure by removing junk URLs and making the origin cheaper to fetch.

Is robots.txt enough to hide a private page?

No. The file is public, and it only asks cooperating crawlers to skip a path. Private pages need authentication. A disallow beside the login URL can save crawl. It does not keep the data private.

Work with me

I read robots.txt as part of a crawl pass: which URLs Googlebot can fetch, which of those answer 410, and which templates send noindex while staying crawlable. If Search Console shows "blocked by robots.txt" on a URL you wanted removed, or production is still serving a staging Disallow: /, that is work I take under technical SEO services.

Send the live robots.txt URL and one URL you want dropped. I will start by checking whether Google is allowed to fetch it.

Discuss this with Muhammad

Message Muhammad Zubair Akhtar on WhatsApp or email [email protected].