How to Create a Robots.txt File Without Blocking the Wrong URLs

A robots.txt file tells cooperative crawlers which URLs they may fetch. It does not secure a URL, and it does not guarantee that a URL will stay out of search results. For most B2B sites, the safe approach is to allow crawling by default, disallow only verified low-value paths, publish the file at the exact site’s /robots.txt location, and test the response that crawlers actually receive.

The underlying standard is the Robots Exclusion Protocol in RFC 9309. Its rules look simple, but a mistake in the host, crawler group, or path can change the result across thousands of URLs.

RFC 9309 defines the top-level robots.txt policy, crawler groups, path-rule matching, and failure handling while explicitly stating that the protocol is not access authorization. [S1]

Confirm that robots.txt is the right control

Choose the control according to the outcome you need:

Required outcomeAppropriate control
Ask compliant crawlers not to fetch selected public URLsrobots.txt
Keep a page out of search resultsA noindex directive on a crawlable page, or the search engine’s removal process
Keep content privateAuthentication, authorization, or network access controls

This distinction prevents a common failure: blocking a page in robots.txt and assuming it has disappeared from search. Google says it may still index a blocked URL when it discovers the URL elsewhere. It also cannot read a page’s noindex directive if robots.txt prevents the page from being fetched. Its official guidance explains both the limits of robots.txt and how indexing directives depend on crawl access.

Google documents that a robots.txt block can leave a discovered URL eligible for indexing and can prevent Google from reading a noindex directive on the blocked page. [S2], [S3]

Never put a confidential path in robots.txt as a security measure. The file is public, so the entry can advertise the path to people and bots that ignore the policy. RFC 9309 explicitly states that the protocol is not access authorization.

Build the file from real URL patterns

Before writing rules, list the site’s actual origins and representative URLs. A policy served from https://www.example.com/robots.txt applies to that protocol and host; it does not automatically cover http://www.example.com, https://example.com, or https://app.example.com. Each origin that needs a policy must serve its own file.

Then classify paths by what crawlers should do. On a typical B2B site, public product, solution, pricing, documentation, and editorial pages normally need to remain crawlable. Internal search results, faceted duplicates, cart flows, or other low-value URL spaces may be candidates for exclusion—but only after checking the site’s real routing and SEO requirements.

This conservative starter file allows the public site and blocks three example directories:

User-agent: *
Allow: /
Disallow: /internal-search/
Disallow: /cart/
Disallow: /checkout/

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

Replace or remove every example path before deployment. User-agent: * targets crawlers without a more specific matching group. Allow and Disallow contain paths relative to the origin. The optional Sitemap line uses an absolute URL and helps supporting crawlers discover the sitemap; Google documents this format in its robots.txt creation guide.

Google’s creation guide documents user-agent groups, Allow and Disallow path rules, top-level file placement, and the fully qualified URL required by a Sitemap field. [S4]

If the site has nothing to exclude, an allow-all rule is valid but not necessary for permission: URLs are crawlable when no applicable rule blocks them. A minimal file may therefore contain only a sitemap declaration, or the site may have no robots.txt file at all. Keep an explicit allow-all group if it makes ownership and operational intent clearer.

Check how the rules will match

Crawlers first select the group matching their product token. If no specific group matches, they use the * group when one exists. A specific group does not inherit rules from the wildcard group. For example:

User-agent: *
Disallow: /reports/

User-agent: ExampleBot
Allow: /

Under the standard, ExampleBot follows its specific group and may crawl /reports/; the wildcard restriction is not added to that group. If that is not the intended result, repeat the restriction inside the specific group.

Path matching begins at the start of the URL path, is normally case-sensitive, and uses the most specific matching rule. That makes slashes and spelling consequential:

User-agent: *
Disallow: /resources/
Allow: /resources/public/

Here, /resources/private/report.pdf is disallowed, while /resources/public/guide.pdf is allowed because the longer rule is more specific. By contrast, Disallow: /resources would also match paths such as /resources-old; use the trailing slash when the intent is a directory boundary.

Avoid clever patterns when explicit prefixes will do. RFC 9309 defines * as a wildcard and $ as an end-of-match marker, but complex patterns are harder to review and easier to misapply. Build test cases for every wildcard rather than relying on visual inspection.

Test the delivered file, not just the repository copy

The file must be named robots.txt, encoded as UTF-8, served as plain text, and available at the lowercase top-level path. After deployment, inspect the live response:

curl -i https://www.example.com/robots.txt

Confirm that the response is successful, the body contains the intended rules rather than an application error page, and the content type is text/plain. Check every relevant host separately.

Response failures can change crawler behavior even when the source file is correct. RFC 9309 allows crawlers to treat an unavailable file, such as many 4xx responses, as having no restrictions; it requires a crawler to assume complete disallow when the file is unreachable because of server or network errors. Individual crawlers document additional handling. For example, Google treats most 4xx responses as no restrictions, reacts differently to 429, and may use a previously cached file during server failures. Google also says it generally caches robots.txt for up to 24 hours. The current details are in Google’s robots.txt parser and status-code documentation.

RFC 9309 defines unavailable and unreachable policy behavior, while Google separately documents its status-code handling, special treatment of 429, and generally 24-hour robots.txt cache. [S1], [S5]

Before release, test at least one URL expected to be allowed and one expected to be disallowed for each affected crawler group. For Google, the robots.txt report in Search Console can test a file that is already accessible. Also verify that the policy does not block CSS, JavaScript, images, or other resources needed to render important public pages.

Record the previous file, the tested URLs, the policy owner, and the rollback condition. After release, watch crawler logs and indexing diagnostics. A correct launch is not merely a syntactically valid text file; it is a live response whose behavior matches the intended URLs on every relevant origin.

Sources

  1. RFC Editor, “RFC 9309: Robots Exclusion ProtocolSupports: The Robots Exclusion Protocol lets service owners request how crawlers access resources through rules served at the top-level robots.txt path; Crawler groups, path matching, Allow and Disallow precedence, wildcard syntax, and unavailable or unreachable file handling are defined by the protocol; Robots.txt is not a form of access authorization. Checked 2026-09-09.Limitation: The protocol is advisory and does not provide authentication, authorization, confidentiality, guaranteed indexing outcomes, or compliance by every crawler.
  2. Google Search Central, “Introduction to robots.txtSupports: Google may index a URL blocked by robots.txt when the URL is discovered elsewhere; Robots.txt is not an appropriate mechanism for protecting private content. Checked 2026-09-09.Limitation: This describes Google Search behavior and does not establish how every crawler handles blocked URLs or indexing.
  3. Google Search Central, “Robots meta tag, data-nosnippet, and X-Robots-Tag specificationsSupports: A crawler must be able to access a page to read its robots meta tag or X-Robots-Tag directives; Blocking crawl through robots.txt can prevent Google from seeing a noindex directive on that resource. Checked 2026-09-09.Limitation: This is Google-specific indexing-control documentation, not a guarantee of removal or a specification for every search engine.
  4. Google Search Central, “Create and submit a robots.txt fileSupports: A robots.txt file uses user-agent groups and Allow or Disallow path rules; A Sitemap field uses a fully qualified absolute URL; The file belongs at the top level of the applicable site and can be tested after it is accessible. Checked 2026-09-09.Limitation: This is Google-specific operational guidance; other crawlers may support different extensions, testing tools, or delivery behavior.
  5. Google for Developers, “How Google interprets the robots.txt specificationSupports: Google documents how HTTP status codes affect its treatment of robots.txt; Google generally caches robots.txt content for up to 24 hours and may use a cached copy during some server failures; Google treats most 4xx responses as no crawl restrictions while handling 429 separately. Checked 2026-09-09.Limitation: This documents Google's parser and failure handling; it does not define the behavior of every crawler or guarantee a fixed cache duration in all conditions.

Continue the evidence path

Run your growth team from one screen.

Invite only