07887 423199me@richieaubin.com

Write and test robots.txt

Use robots.txt to manage crawling. Keep sensitive pages behind access controls. A publicly accessible URL that is blocked from crawling can still appear in search if a search engine discovers it elsewhere.

Robots.txt rules example
Example image · CC0 1.0 licence

Choose a way to do this check

Robots.txt tester on this site

  1. Paste the policy and use the exact crawler token. Add expected allowed and blocked examples.
  2. Review the matching group and line number. Confirm that the pasted policy belongs to the tested origin.

Screaming Frog configuration

  1. Crawl a bounded public sample with robots handling recorded.
  2. Compare blocked results with your intended routes and inspect important resources separately.

Google Search Console robots report

  1. Select the matching property and review the file Google last fetched and any fetch issues.
  2. Compare the stored file and date with the current public robots.txt response.
Example robots.txt test: compare a blocked sort parameter with a specific Allow rule for an approved guide.
Example robots.txt test: compare a blocked sort parameter with a specific Allow rule for an approved guide.

1. List the URLs you expect crawlers to use

Before editing, save the current file and choose both a URL you want crawled and a pattern you want to restrict. Include a resource required to render your main content. If the site has several live hostnames or protocols, check each one separately. A robots file applies to the site location where it is served, including its scheme, host and port.

2. Add a narrow rule at the site root

Serve plain text at /robots.txt. The example limits crawling of an internal search folder for general crawlers and points to the preferred host's sitemap. Replace the path and URL and merge the rule with the existing groups.

Web root · robots.txt
User-agent: *
Disallow: /internal-search/

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

The trailing slash is intentional. Test the slashless route separately if it exists. A named crawler group can have different rules from the generic group. Do not assume a restriction in the generic group is inherited by a more specific group. Test the file against the relevant crawler's published interpretation.

3. Check the live response

Use this command after a staging deployment or after publishing a reviewed change. Look for a successful response and make sure you get the robots file rather than a CDN challenge, placeholder or login page.

Terminal · fetch the robots file from the live host
curl -sS --max-time 15 -D robots-headers.txt \
  -o robots-live.txt https://www.example.com/robots.txt
cat robots-headers.txt
sed -n '1,50p' robots-live.txt

A successful response confirms delivery only. Check the intended results using a parser or report appropriate to the crawler. Validate exact paths, path case and URL variants that could match a rule unexpectedly. Save the sample checks so the next edit can be compared.

Sample test matrix · replace with your routes
crawler,path,expected_crawl_rule
Googlebot,/internal-search/?q=lamp,blocked
Googlebot,/lighting/,allowed
Googlebot,/assets/main.css,allowed
Googlebot,/internal-search-help/,allowed

4. Recheck search and AI access independently

Record which crawler group you changed and why. If you manage AI bot policies, use each provider's documentation to distinguish search crawling, training and user-triggered fetching. A crawl permission allows a request under that policy. It does not guarantee a page will be indexed, selected or cited. Check CDN or firewall restrictions separately if authorised requests are still denied.

5. Roll back a rule that blocks too much

Restore the previous file if important routes or rendering assets are blocked. Check the live body on the affected hostname, then re-run the positive and negative cases. A crawler may use a cached copy of the file for a period, so allow for that when comparing follow-up logs and search reports.

Technical references

Frequently asked questions

Does robots.txt remove pages from search?

It controls crawling. For a public URL you want removed from Google's index, use a crawlable noindex response or a permanent removal response as appropriate.

Can robots.txt protect private data?

No. Use authentication or durable access controls.

Do I need one file for each subdomain?

Check each hostname separately. A file on the main host does not govern a different subdomain.

Is the URL of the sitemap optional?

Yes. Adding the Sitemap line can help engines discover the file, alongside submission via webmaster tools.

Written by Richie Aubin

Published