robotstxt
Key Takeaways
- robots.txt is a plain-text file placed at your domain root (e.g., https://example.com/robots.txt) that gives crawling instructions to web crawlers.
- It controls crawling, not indexing; a URL blocked in robots.txt can still appear in search results if linked externally.
- Directives include
User-agent,Disallow,Allow,Sitemap, andCrawl-delay(supported by some bots). - Syntax mistakes—such as missing slashes, wildcard misuse, or blocking CSS/JS—can unintentionally hide your entire site from search engines.
- Always validate changes with Google Search Console's robots.txt tester and monitor crawl stats after deployment.
robots.txt: The Complete Problem-Solver Guide
A misconfigured robots.txt file is one of the most common—and costly—technical SEO mistakes. Because it sits at the gateway between your site and every crawler on the web, a single line can accidentally de-index thousands of pages or, conversely, waste crawl budget on low-value URLs. This guide answers the real-world pain points practitioners face when creating, auditing, and maintaining robots.txt.
What Is robots.txt and Why Does It Matter?
robots.txt is part of the Robots Exclusion Protocol (REP). When a crawler visits your site, it first requests /robots.txt. The file returns rules that tell the crawler which paths it may or may not request. It is not an access-control mechanism and does not protect private data; determined crawlers and malicious bots may ignore it entirely.
Core Directives at a Glance
- User-agent: Specifies which crawler the rules apply to (e.g.,
*for all,Googlebotfor Google). - Disallow: Paths the crawler must not request.
- Allow: Overrides a broader Disallow for a specific path (Google and Bing support this).
- Sitemap: Declares XML sitemap locations.
- Crawl-delay: Requests a delay between requests (not supported by Googlebot).
Problem 1: "My Important Pages Aren't Being Crawled or Indexed"
Pain point: You published new content, but Google hasn't discovered it, or Search Console shows "Blocked by robots.txt."
Diagnosis and Fix
- Open
https://yourdomain.com/robots.txtand search for the affected path. - Check for overly broad rules like
Disallow: /orDisallow: /*?that may catch query parameters used for pagination or filtering. - Verify you are not blocking resources crawlers need to render pages (CSS, JS, images).
- Ensure the file is served with HTTP 200 and
text/plaincontent type—not a 404 or redirect. - Submit the URL in Google Search Console's URL Inspection tool and request indexing.
Problem 2: "How Do I Protect Admin, Staging, or Sensitive Areas?"
Pain point: You want to keep crawlers out of /wp-admin/, /staging/, or internal search results without breaking SEO.
Recommended Approach
- Block crawlable but non-public areas with
Disallow: /staging/andDisallow: /search?. - For truly sensitive data, rely on authentication and server-level access controls—not robots.txt.
- Use
noindexmeta tags or X-Robots-Tag headers for pages that must not appear in search results even if crawled. - Avoid blocking entire directories that contain assets needed for rendering public pages.
Problem 3: "What's the Difference Between robots.txt, Meta Robots, and X-Robots-Tag?"
Pain point: Teams often confuse these tools and apply the wrong one, causing either index bloat or accidental de-indexing.
| Method | Scope | Controls Crawling? | Controls Indexing? | Best For |
|---|---|---|---|---|
| robots.txt | Site-wide / path-based | Yes | No (indirectly) | Managing crawl budget, blocking non-public areas |
| Meta robots tag | Per HTML page | No | Yes | Preventing specific pages from appearing in search results |
| X-Robots-Tag header | Per HTTP response (any file type) | No | Yes | Non-HTML assets (PDFs, images) and dynamic responses |
Problem 4: "My robots.txt Has Syntax Errors or Wildcard Issues"
Pain point: Google ignores malformed rules, and pattern matching with * and $ behaves differently than expected.
Common Mistakes and Corrections
- Missing leading slash: Use
Disallow: /admin/, notDisallow: admin/. - Overusing wildcards:
Disallow: /*.pdf$blocks PDFs; ensure you intend to block all of them. - Blocking parameters incorrectly:
Disallow: /*?sort=may be too broad; test with Google's tester. - Multiple User-agent blocks: Group rules logically; conflicting blocks can confuse parsers.
- Comments: Lines starting with
#are ignored—use them to document intent.
Implementation Checklist
- Place robots.txt at the root domain and ensure it returns 200 OK.
- Include a
Sitemap:directive pointing to your XML sitemap. - Block only low-value or non-public paths (admin, cart, search, staging).
- Never block CSS, JavaScript, or image assets needed for rendering.
- Use Allow to carve exceptions out of broad Disallow rules.
- Test with Google Search Console and Bing Webmaster Tools.
- Review after site migrations, CMS updates, or new subdomain launches.
- Monitor crawl stats and index coverage reports weekly for anomalies.
FAQ
1. Does blocking a URL in robots.txt remove it from Google search results?
No. robots.txt prevents crawling but not indexing. If other sites link to the URL, Google may still index it (often without a snippet). To remove a page from results, use a noindex directive via meta robots or X-Robots-Tag, and ensure the page is crawlable so Google can see the directive.
2. Where should robots.txt be located?
It must reside at the root of your host: https://www.example.com/robots.txt. Subdomains require their own file (e.g., https://blog.example.com/robots.txt). It cannot be placed in a subfolder and still be honored by standard crawlers.
3. Is robots.txt case-sensitive?
Path matching is case-sensitive for some crawlers, including Googlebot. Disallow: /