What Is a Robots.txt File?
A robots.txt file is a plain-text file placed in the root directory of a website. It provides crawling instructions to web crawlers that choose to follow the Robots Exclusion Protocol.
For example, a website at https://example.com normally serves its robots.txt file at https://example.com/robots.txt.
Website owners use this file to guide crawler access to particular paths, reduce unnecessary crawling, and declare sitemap locations. It is a crawler instruction file, not a security mechanism.
Common Robots.txt Directives
User-agent
Identifies the crawler or group of crawlers to which the following rules apply. An asterisk represents all crawlers covered by the rules.
Disallow
Specifies a URL path that the selected crawler is asked not to access.
Allow
Specifies a path that a crawler may access, including cases where a more general Disallow rule also applies.
Sitemap
Provides the location of an XML sitemap to help search engines discover URLs on the website.
Robots.txt Example
The following is a basic example of a robots.txt file. Adjust the paths and sitemap address to match your actual website structure.
User-agent: *
Disallow: /admin/
Disallow: /private/
Sitemap: https://example.com/sitemap.xml
In this example, the rules ask matching crawlers not to access the specified paths. The sitemap declaration provides a location where crawlers can discover the website's sitemap.
Important Robots.txt Rules to Understand
- File location matters: A robots.txt file applies to the protocol, hostname, and port where it is published. Place it at the root of the relevant website.
- Disallow is a crawl instruction: It asks compliant crawlers not to fetch matching URLs. It does not provide password protection or restrict access for ordinary visitors.
- Rules are crawler-specific: Different crawlers may interpret or support directives differently. Do not assume every bot follows the file.
- Rule order and specificity matter: When rules overlap, supported crawlers use their matching and precedence rules to determine which instruction applies.
- Keep important resources accessible: Blocking CSS, JavaScript, or other resources that search engines need to understand a page can interfere with rendering and evaluation.
- Use valid sitemap URLs: Reference the correct sitemap location and check that the sitemap can be accessed.
Robots.txt vs. Noindex: What Is the Difference?
This is one of the most important distinctions in technical SEO. Robots.txt controls crawler access to URL paths. A noindex directive tells supported search engines not to include a page in their search results after they crawl and discover that directive.
If a page is blocked by robots.txt, Google may not be able to crawl it and see a noindex instruction placed on that page. The URL can still appear in search results if discovered through other links or sources.
Use Robots.txt
When your goal is to manage crawler access to selected paths or reduce unnecessary crawling.
Use Noindex
When your goal is to prevent a page from appearing in supported search engines' search results. The crawler must be able to access the page and see the directive.
For confidential information, use authentication or proper access controls. Neither robots.txt nor noindex should be treated as a way to secure private content.
Common Robots.txt Mistakes
- Blocking important pages or entire website sections accidentally.
- Using robots.txt to try to remove URLs from search results instead of implementing noindex correctly.
- Blocking CSS or JavaScript resources needed to render important pages.
- Referencing an incorrect or inaccessible sitemap location.
- Publishing the file in the wrong directory or on the wrong hostname.
- Assuming every crawler supports every directive in the same way.
- Making changes without testing how important URLs are affected.
How to Maintain Your Robots.txt File
- Keep a backup of the existing robots.txt file before editing it.
- Identify which website paths should and should not be crawled.
- Write clear rules for the intended crawlers.
- Check that important pages and resources are not accidentally blocked.
- Verify the sitemap URL and confirm the sitemap is accessible.
- Test important URLs with appropriate crawler and search console tools.
- Recheck the file after website migrations, URL changes, or major technical updates.
Frequently Asked Questions
Where should robots.txt be located?
For a website such as example.com, the standard location is the root path: https://example.com/robots.txt. A file placed in a subdirectory does not control crawling rules for the entire hostname.
Does robots.txt prevent Google from indexing a page?
Not reliably. Robots.txt controls crawling, not guaranteed removal from search results. A blocked URL may still be indexed without its page content if Google discovers it elsewhere. Use a noindex directive when your goal is to prevent indexing, and allow Google to crawl the page to see that directive.
Can robots.txt protect private files?
No. Robots.txt is publicly accessible and relies on crawlers choosing to follow its instructions. Protect private files and restricted areas with authentication and server-side access controls.
Should I block my entire website from crawlers?
Only when you have a specific reason, such as a private or staging environment. Blocking an active public website can prevent search engines from crawling important pages and resources.
Does every search engine follow robots.txt?
No. Robots.txt instructions are voluntary and crawler support varies. Reputable search crawlers generally respect supported rules, but malicious bots and other automated visitors may ignore them.
How often should I check robots.txt?
Review it after website migrations, changes to URL structures, new SEO settings, or major technical updates. Periodic checks can also help identify accidental restrictions.