SEO & Google Search

Robots.txt Explained: How to Configure It for Google and Search Engines

Understand robots.txt rules, Googlebot crawling, Disallow and Allow directives, sitemap references and common configuration mistakes.

Complete guideRobots.txtTechnical SEO

The robots.txt file is a small but important part of website technical SEO. It gives instructions to automated crawlers about which areas of a website they may request. A simple mistake in this file can unintentionally restrict search engine crawling.

Whether you manage a WordPress website, business website, blog or online store, it is worth understanding how robots.txt works before changing its rules. This guide explains the file, common directives, examples and ways to check your configuration.

What robots.txt does

🌐
WebsitePublishes a robots.txt file at its root.
📋
InstructionsLists rules for crawler user agents.
🤖
CrawlerReads and follows applicable rules.
🧭
RequestsRespects disallowed paths when supported.

1. What Is a Robots.txt File?

A robots.txt file is a plain-text file placed at the root of a website. It contains rules that tell compatible web crawlers which URL paths they are allowed or not allowed to request.

For example, a website with the domain example.com commonly makes its robots.txt file available at:

https://example.com/robots.txt

Search engines and other automated crawlers may check this file before crawling parts of a website. The rules are instructions for crawlers, not access controls that secure private information.

2. Why Is Robots.txt Important for SEO?

Robots.txt can help website owners manage crawler access to areas that do not need to be crawled. It can also help avoid wasting crawler requests on unimportant or repetitive URL paths.

🧭

Guide crawler access

Tell compatible crawlers which URL paths they should avoid requesting.

⚙️

Manage crawl activity

Reduce crawling of selected areas that do not need search discovery.

🗺️

Reference a sitemap

Include the absolute URL of an XML sitemap to help crawlers discover it.

Important distinctionRobots.txt controls crawling, not guaranteed indexing. A URL blocked by robots.txt may still appear in search results if Google discovers it through other signals. Do not use robots.txt as a reliable way to remove a page from Google's index.

3. Where Is the Robots.txt File Located?

For a website at example.com, the standard location is:

https://example.com/robots.txt

The file belongs at the root of the relevant host. A robots.txt file for the main domain does not automatically control a different subdomain. For example, www.example.com and shop.example.com are separate hosts for robots.txt purposes.

Open your own robots.txt URL in a browser to see the current instructions. If the file does not exist, the server may return a 404 response; that does not automatically mean your website cannot be crawled.

4. Understanding the Main Robots.txt Directives

User-agent

Identifies the crawler that a group of rules applies to. An asterisk (*) means the group applies to all crawlers that follow the robots exclusion protocol.

Disallow

Specifies a path that the matched crawler should not request.

Allow

Can be used to allow a more specific path within a broader disallowed path. Support and rule interpretation can vary between crawlers.

Sitemap

Provides the absolute URL of an XML sitemap. Sitemap declarations are useful discovery hints and are not limited to a particular user-agent group.

Comments

A line beginning with # is a comment and is ignored by crawlers that support the standard syntax.

5. Common Robots.txt Examples

Allow all crawlers to access the website

User-agent: * Disallow:

This leaves the disallow path empty, meaning no paths are disallowed by this group.

Block a specific directory

User-agent: * Disallow: /private-area/

This asks compatible crawlers not to request URLs under that path. It does not make the directory private or secure.

Reference an XML sitemap

Sitemap: https://example.com/sitemap_index.xml

Use the actual sitemap URL for your website. The sitemap declaration should be an absolute URL.

Combine a disallow rule with a sitemap reference

User-agent: * Disallow: /wp-admin/ Allow: /wp-admin/admin-ajax.php Sitemap: https://example.com/sitemap_index.xml

This is an illustrative pattern sometimes used on WordPress websites. Check your actual website requirements and plugin behaviour before copying it.

6. Robots.txt on WordPress Websites

WordPress can provide a virtual robots.txt response when a physical file is not present. SEO plugins may also offer controls for editing robots.txt rules.

To check your WordPress website:

  1. Open your domain followed by /robots.txt.
  2. Review the rules shown in the browser.
  3. Check whether the file is physical or generated by WordPress or a plugin, if you need to edit it.
  4. Review SEO plugin settings before making changes.
  5. After editing, open the URL again and confirm the new content is being served.
Be careful with WordPress admin pathsA common configuration blocks crawling of /wp-admin/ while allowing admin-ajax.php. Do not block the entire website or important public resources by mistake. Also remember that robots.txt is not a security feature.

7. Common Robots.txt Mistakes

MistakeWhy it matters
Disallow: /Can block compatible crawlers from requesting the entire site.
Blocking important CSS or JavaScriptMay prevent crawlers from accessing resources needed to understand the page.
Using robots.txt to hide private filesThe file is public and does not prevent direct access.
Trying to remove indexed URLs with DisallowA blocked URL may still be indexed without its content.
Wrong sitemap URLCrawlers may not find the intended sitemap.
Editing the wrong host's fileEach host needs its own applicable robots.txt file.

8. Robots.txt vs Noindex: What Is the Difference?

These are different controls and should not be used interchangeably.

Robots.txtNoindex directive
Controls whether compatible crawlers should request a URL path.Instructs search engines not to include a page in search results when they can crawl and process the directive.
Does not reliably remove a URL from the index.Can be used to request exclusion from search results.
Is publicly accessible as a text file.Can be provided in page HTML or an HTTP X-Robots-Tag header.
Critical ruleIf you want Google to see a noindex instruction, do not block that page from crawling in robots.txt. Google needs to access the page or response header to read the directive.

9. Is Robots.txt a Security Tool?

No. Robots.txt is not a password, firewall or access-control system. Anyone can open the file and read its contents. Disallowed paths are also visible to the public.

Do not list sensitive file locations in robots.txt as a way to protect them. Use authentication, server permissions and appropriate access controls to protect private information.

10. How to Check and Test Your Robots.txt File

  1. Open https://yourdomain.com/robots.txt.
  2. Check that the file returns the expected text.
  3. Review every User-agent, Disallow and Allow rule.
  4. Confirm important public pages and resources are not unintentionally blocked.
  5. Check that any sitemap declaration uses the correct full URL.
  6. Use the relevant search engine's current tools and reports to investigate crawling issues.

Google Search Console's URL Inspection and Page Indexing reports can help you understand whether Google can access and process particular URLs. Do not rely on outdated third-party robots testing tools as the only source of truth.

11. Robots.txt Checklist

12. Check Your Website's Crawling and Technical SEO

Robots.txt is one part of a website's search engine accessibility. A website should also have working pages, suitable indexing directives, correct canonical URLs and an accessible XML sitemap.

Website Doctor's free homepage inspection includes checks for robots.txt and XML sitemap availability, along with other technical elements such as website availability, canonical URL and indexing directive.

Check Your Website's Technical Health

Run a free Website Doctor scan to review important technical elements of your homepage.

Run a Free Website Scan

Frequently Asked Questions

What is robots.txt used for?

Robots.txt provides instructions to compatible crawlers about which URL paths they should or should not request.

Where should robots.txt be located?

It should be placed at the root of the relevant host, for example https://example.com/robots.txt.

Does robots.txt prevent Google from indexing a page?

Not reliably. A blocked URL may still appear in search results if Google discovers it elsewhere. Use an appropriate noindex directive when you want a crawlable page excluded from search results.

Can robots.txt protect private files?

No. The file is public and does not restrict direct access. Use authentication and proper server access controls for private information.

Should I block wp-admin in WordPress?

Many WordPress configurations disallow crawling of /wp-admin/ while allowing admin-ajax.php. Review your site's needs and avoid blocking important public resources.

Can I include my sitemap in robots.txt?

Yes. You can add a Sitemap line containing the full absolute URL of your XML sitemap.

What does Disallow: / mean?

It tells compatible crawlers not to request paths under the host covered by that robots.txt rule. Use it carefully because it can block the entire website from crawling.

Does every website need robots.txt?

A website can be crawled without a robots.txt file. The file is useful when you need to provide crawler instructions, but it is not mandatory for every site.

Final Thoughts

Robots.txt is a simple file, but its rules can affect how search engine crawlers access your website. Keep the configuration clear, avoid blocking important public content and never use robots.txt as a security method or a guaranteed way to remove pages from search results.

Review your robots.txt file whenever you change website structure, install an SEO plugin or troubleshoot crawling problems. If you are unsure about a rule, understand its effect before publishing it.