A robots.txt file gives automated crawlers instructions about which URL paths they may request from a website. A careful file can reduce unnecessary crawling and keep crawlers away from low-value areas. One incorrect line, however, can block important pages or the CSS and JavaScript needed to understand them.
Robots.txt controls crawling; it is not a reliable way to keep a web page out of search results, protect private information, or guarantee rankings. This guide explains the rules in plain language and provides a safe testing workflow.
What Is robots.txt?
Robots.txt is a UTF-8 plain-text file that follows the Robots Exclusion Protocol. It contains groups of rules addressed to automated clients called user agents. Compliant crawlers normally request the file before accessing URLs on the same protocol, host, and port.
Google’s official robots.txt introduction says its main purpose is managing crawler traffic, not preventing a page from appearing in Google. Respectable crawlers follow the rules, but malicious bots may ignore them.
Where Must robots.txt Be Located?
The file must be named robots.txt and placed at the root of the host it controls:
https://example.com/robots.txt
A file at https://example.com/folder/robots.txt does not control the whole site. Rules are specific to protocol, hostname, and port. Therefore, https://example.com/robots.txt does not automatically govern http://example.com/ or https://shop.example.com/.
Open the address in a private browser window. It should be publicly accessible as plain text without authentication or a redirect loop.
How Search-Engine Crawlers Use It
A crawler downloads robots.txt, identifies the rule group matching its user-agent token, and compares a requested URL path with that group’s rules. URLs not blocked by a matching Disallow rule are allowed by default.
Different crawlers may support different syntax. This article describes Google’s documented interpretation, but site owners should check the documentation of every crawler that matters to them.
Understanding User-agent
User-agent begins a rule group and identifies the crawler. An asterisk targets crawlers that match the general group:
User-agent: *
Disallow: /private-area/
A crawler-specific group can define different access. Avoid copying long lists of crawler names without understanding them. Misspelled tokens and contradictory groups make maintenance difficult.
Understanding Disallow and Allow
Disallow
Disallow identifies a path a matching crawler should not request:
User-agent: *
Disallow: /temporary-reports/
Paths are case-sensitive. /Files/ and /files/ can be different. An empty Disallow: blocks nothing; Disallow: / blocks the entire host for that group and must be handled with extreme care.
Allow
Allow can create an accessible exception inside a blocked path:
User-agent: *
Disallow: /assets/
Allow: /assets/public/
Google evaluates matching rules using path specificity. Test real URLs rather than assuming the order alone determines the result.
Adding a Sitemap Directive
A robots.txt file can identify one or more XML sitemaps with fully qualified URLs:
Sitemap: https://example.com/sitemap.xml
The sitemap line is independent of a user-agent group. It helps crawlers locate the sitemap but does not override blocked paths or guarantee crawling and indexing. See the XML sitemaps guide for canonical URL and submission guidance.
What robots.txt Can Do
- manage access by compliant crawlers;
- reduce crawling of unimportant or repetitive URL spaces;
- apply separate rules to supported user agents;
- allow exceptions inside a blocked directory; and
- advertise sitemap locations.
This can be useful on large sites with filtered navigation, internal result pages, or crawler-heavy sections. Small sites often need only a simple file.
What robots.txt Cannot Do
- It cannot keep confidential information secure.
- It cannot force every bot to obey.
- It cannot reliably prevent a URL from appearing in search.
- It cannot remove an indexed URL immediately.
- It cannot act as a canonical signal.
- It cannot guarantee better rankings or a particular crawl frequency.
A blocked URL can still be known through external links and may appear without a descriptive snippet. Use authentication or access controls for private material.
robots.txt vs noindex
Robots.txt controls whether a crawler may request a URL. A noindex meta tag or HTTP header tells a supported search engine not to include the page in its index.
If robots.txt blocks the page, Google may be unable to crawl it and see its noindex directive. To remove a crawlable public page from search, allow crawling and apply noindex, then wait for recrawling. For confidential information, use authentication rather than either method.
The canonical URL guide explains why robots.txt, canonicalization, and noindex solve different problems.
Why Blocking CSS and JavaScript Can Cause Problems
Modern pages often need stylesheets and scripts to render menus, responsive layouts, content, or navigation. If essential resources are blocked, a crawler may see an incomplete page and misunderstand its mobile usability or content.
Do not block an entire assets, theme, or plugin directory simply because the files are not search results. Confirm which resources are essential to rendering. Use Search Console URL Inspection and its live test to compare the rendered page when diagnosing a problem.
A Safe robots.txt Example
User-agent: *
Disallow: /internal-search/
Allow: /
Sitemap: https://example.com/sitemap.xml
This example asks general crawlers not to request one internal-search path, permits other paths, and identifies the sitemap. It is only an illustration: rules must match the actual site structure, and unnecessary lines should be omitted.

How to Test robots.txt
- Open the file directly. Confirm the root URL returns accessible plain text.
- Review the exact host. Check protocol, hostname, subdomain, and port.
- Check syntax. Use one directive per line and standard straight characters.
- Test representative URLs. Include the homepage, articles, images, CSS, JavaScript, and every intended blocked area.
- Use Search Console. Review the robots.txt report and URL Inspection where available.
- Check server logs when appropriate. Confirm crawler behavior without assuming every bot obeys.
- Deploy cautiously. Retest immediately after migration, staging launch, CDN change, or plugin update.
Google’s current creation and testing documentation recommends making the file publicly accessible and using the Search Console robots.txt report for a live file.
Common robots.txt Mistakes
- Leaving a staging block after launch:
Disallow: /can stop crawling across the site. - Using robots.txt for privacy: The file is public and untrusted bots can ignore it.
- Blocking a noindex page: Crawlers may never see the directive.
- Blocking essential assets: Important pages may render incorrectly.
- Placing the file in a subfolder: It must be at the host root.
- Assuming one file covers subdomains: Each host needs its own applicable file.
- Using full URLs in Disallow: These rules normally use paths beginning with
/. - Forgetting case sensitivity: The rule must match the actual path.
- Copying another site’s file: Its structure and risks are different.
- Changing rules without testing: A small error can affect large sections.
Practical Beginner Checklist
- The file is available at
/robots.txt. - It is valid UTF-8 plain text.
- Rules apply to the intended protocol, host, and port.
- Every rule group begins with the correct user agent.
- No accidental sitewide block exists.
- Important pages are crawlable.
- Required CSS, JavaScript, and images are crawlable.
- Private content uses real access control.
- Noindex pages are available to crawlers that must see the directive.
- Sitemap directives use complete correct URLs.
- Representative URLs have been tested.
- The file is rechecked after major technical changes.
Include robots.txt review in a broader SEO audit alongside response codes, canonicals, sitemaps, internal links, and rendered pages.
Frequently Asked Questions
Does every website need robots.txt?
No. When no file exists, crawlable URLs are generally allowed by default. A file is useful when you need explicit traffic-management rules or want to advertise a sitemap.
Can robots.txt remove a page from Google?
Not reliably. A blocked URL may still appear if Google discovers it elsewhere. Use a crawlable noindex directive, authentication, or removal of the content according to the actual goal.
Should WordPress block its admin area?
Many installations include a rule for administrative paths while allowing required public endpoints. Do not copy a rule blindly; verify the site’s configuration and whether public features depend on a path.
How quickly do rule changes apply?
There is no universal instant timeline. Crawlers cache and periodically refetch the file. Test the live file and use supported refresh or reporting tools when an urgent correction is needed.
Keep Crawler Rules Simple and Testable
A good robots.txt file is usually short, intentional, and easy to test. Use it to manage crawler access—not as a privacy tool, an indexing guarantee, or a shortcut for repairing site architecture.
Before every change, identify the exact crawler and path, test important pages and resources, and keep indexing controls separate. That discipline prevents one small text file from causing a large visibility problem.
