Where the File Lives: Robots.txt example
Your robots.txt file must be located at the root of your domain, accessed at yourdomain.com/robots.txt. It shouldn’t be in a subdirectory and shouldn’t be named anything other than robots.txt. Crawlers will look for this file in this exact location.
You can check any site's file by visiting its URL directly. Try `google.com/robots.txt` and you'll see a real one. If yours returns a 404, crawlers assume there are no restrictions and crawl everything, which is often fine for a simple site.
Ready-to-Copy Robots.txt Examples
Here are the most common setups. Pick the one that matches your situation and adjust the paths.
Allow everything (the default)
This directive allows all crawlers to access all pages on your site.
User-agent: *
Disallow:
Sitemap: https://yourdomain.com/sitemap.xml An empty disallow directive means no pages are blocked.
Block a specific folder
Used to block admin or internal pages from being indexed. Can be used to block a staging folder from being indexed.
User-agent: *
Disallow: /admin/
Disallow: /private/
Sitemap: https://yourdomain.com/sitemap.xml By default crawlers have been instructed not to access admin and private pages.
Block everything (use with care)
This hides your whole site from all crawlers. Use it only for a site that isn't ready to be found.
User-agent: *
Disallow: / That single slash blocks the entire site. More sites have accidentally deployed this than anyone would like to admit. Double-check before you ship it.
Block one specific crawler
To exclude a single bot from accessing a site.
User-agent: BadBot
Disallow: /
User-agent: *
Disallow: This first line blocks access to the BadBot entirely. The second line grants access to all other bots.
A typical WordPress robots.txt
A sensible default for a WordPress site.
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Sitemap: https://yourdomain.com/sitemap.xml Blocks the admin area of a site. Allows one file in the admin area which may be accessed by the public site pages.
Every Directive Explained
Four directives do almost all the work. Here's what each one means.
| Directive | What it does |
|---|---|
| User-agent | Names which crawler the rules apply to; `*` means all |
| Disallow | Blocks access to a path; empty means block nothing |
| Allow | Permits a path, often an exception inside a blocked folder |
| Sitemap | Points crawlers to your XML sitemap |
User-agent
This controls which user agent the following rules apply to. Use * to mean all user agents. To only target Google’s user agent, use User-agent: Googlebot.
Disallow
This instructs crawlers not to access the admin area of the site. Use / at the beginning and end of a path to indicate the path starts at the root of the domain. An empty Disallow directive indicates that no files are blocked. Disallow: / blocks all files.
Allow
If you block a directory using the Disallow directive, you can Allow single files within that directory to be crawled.
Sitemap
This points crawlers to your sitemap, which shows pages you want found. It’s not a restriction. Sitemaps are a good thing. Including your sitemap here won’t hurt anything and you can include many if you want to.
Common Mistakes to Avoid
These are the serious issues that you want to be aware of.
Accidentally blocking your entire site. Leaving a Disallow: / directive during a staging site setup is a classic instance of a disastrous SEO fiasco. After going live always check your robots.txt to make sure it’s not blocking everything.
Thinking Disallow means "don't index." It doesn't. Disallow stops crawling, but a blocked page can still appear in search results if other sites link to it, just without a description. To truly keep a page out of the index, use a noindex meta tag. Don't block it in robots.txt, because then Google can't see the noindex.
Blocking CSS and JS. You used to see recommendations to block these on sites. Don't. Google has to render your page to grasp it. If you block your stylesheets or scripts it can't. Blocking them will affect Google's ability to grasp your site.
Case sensitivity. User agents can be very case sensitive. It is better to be exact. For instance using both /Admin/ and /admin/ will be interpreted as two different directories.
Using it for security. Robots.txt is public and only requests cooperation. Bad bots ignore it, and listing a "secret" folder there actually advertises it. Never rely on it to protect sensitive content. use real authentication.
A Real-World Example
Say you launch a new site and traffic never comes. Weeks pass with zero organic visits. You can't figure out why. You finally check `yourdomain.com/robots.txt` and find this, left over from development:
User-agent: *
Disallow: / There it is. During development a web coder blocked all user agents to prevent Google from crawling and indexing the site. They forgot to remove the block during the launch. You changed the Disallow entry to an empty string, submitted a new Sitemap via Search Console. Within a few days Google began crawling and indexing your site. The whole process took about three weeks. Finding the problem only took about thirty seconds.
This happens all the time. Robots.txt is the first file you should check when trying to troubleshoot why a site isn't ranking.
How to Test Your Robots.txt
Never guess whether your file works. Test it. [Google Search Console](here includes a robots.txt report that shows what Googlebot sees and flags errors. For the official rules, [Google's robots.txt documentation](here is the authoritative reference. The free [Denwix tools](here can also help you inspect your site's files.
After editing your file, always view the live version to make sure the changes were implemented correctly.
The Bottom Line
A robots.txt file should mostly allow all. Disallow specific folders. Use the ‘block all’ version only if the site is still under construction. ‘Disallow’ tells search engine bots not to crawl certain pages. Keep stylesheets and javascript files uncrawlable. The robots file should never be used for security purposes. Remember to test the changes you’ve implemented and that one line of ‘Disallow: /’ can potentially cost you weeks of traffic.
Questions and Answers
What is a robots.txt file?
A robots.txt file is very small and can be edited using a plain text editor. Use the ‘allow all’ rule and disallow specific sections to be crawled. ‘Disallow’ does not prevent a page from being indexed. The majority of search engine crawlers are respectful of robots.txt. Be sure to test changes to this file.
Where should the robots.txt file be located?
At the root of your domain, reachable at yourdomain.com/robots.txt. It must be at the root, not in a subfolder. Crawlers won't find it.
What is a basic robots.txt example?
A simple robots.txt file is one that allows all crawlers to access all files using the rule ‘User-agent: *’ followed by ‘Disallow:’
How do I block a page in robots.txt?
Add a Disallow line with the path like “Disallow: /folder/”. Remember this will just stop crawling, not indexing. To prevent a page from appearing in search results use a meta tag with attribute “name” or “content” set to “noindex”.
What does "Disallow: /" mean?
Adding this line to a robots.txt file will block crawling for all search engines. Use this only if the site is not complete and you don’t want it listed in any search results.
Does robots.txt stop a page from being indexed?
No. Robots.txt will stop crawling of that page. That page may still appear in search results if other sites link to that page. To keep a page from search results use the meta tag “noindex”.
What is the difference between Disallow and noindex?
Using the directive “Disallow” in robots.txt will stop crawling of that page, while using the meta tag “noindex” on that page will stop that page from appearing in search results.
Can I block a specific crawler?
Yes, you can add “User-agent: BadBot” to specify which bot you want to block and then add “Disallow: /” to block that bot from all pages on the site.
Should I block CSS and JavaScript in robots.txt?
No. Stopping those from loading will impact how search engines interprets and ranks your page.
Is robots.txt case-sensitive?
Yes. For instance “/Admin” and “/admin” will be considered different from each other. To ensure your rules work properly case sensitivity of your site’s paths must be preserved.
How do I add a sitemap to robots.txt?
Add “Sitemap: here Repeat this for each of your site’s sitemaps.
What does User-agent mean in robots.txt?
This rule set applies to the crawler identified here. Asterisks show all crawlers. For instance, a rule with Googlebot means only Google’s crawler would be affected by that rule.
Can robots.txt protect private content?
No. The file is publicly ready and requests voluntary compliance. Malicious crawlers will ignore the robots.txt file and listing a folder in the robots.txt file reveals the folder. To prevent bots from accessing sensitive details on your site use authentication.
What happens if I don't have a robots.txt file?
Crawlers assume there are no restrictions and will crawl your entire site. For smaller sites this isn't an issue. A site may function well without a robots.txt file.
How do I test my robots.txt file?
Use the Google Search Console to see what Google is reading and correcting mistakes in your robots.txt file. You can also check the robots.txt file directly to see if there are any errors.
Can I allow a file inside a blocked folder?
Yes. For instance, you could include a Disallow rule to block a directory. Then include an Allow rule to specify that specific file should be crawled. For instance, one could disallow the wp-admin directory and allow crawling of the file admin-ajax.php.
Why is my whole site blocked from Google?
Most likely a leftover “Disallow: /” from development. This is probably blocking your site from being crawled. Go to your live robots.txt, change it to allow crawling. Then submit your sitemap again in Search Console.
How often do crawlers check robots.txt?
Crawlers fetch the file and cache it before each crawl. Changes may take a while to show up as crawlers use the cached version.
Can I have comments in robots.txt?
Yes. Anything after a # on a line is ignored by a crawler and can be used to describe and organize rules and sections in the file.
Does every website need a robots.txt?
Not necessarily. A small site could certainly work without one. A robots.txt file containing your sitemap would be considered good practice.
Can I block Googlebot but allow Bing?
Yes. Add a block mainly for Googlebot to include a Disallow and blocks for other crawlers to include Allows. Each User-Agent section only affects the crawler named in that section.
What is a crawl-delay directive?
Google will ignore crawl-delay directives. Others may not. You should use your server to control Google’s crawl rate.
Does robots.txt affect images and PDFs?
Yes. You can exclude paths to files to block crawlers from accessing them. Keep in mind this won’t prevent them from appearing in search results if they are linked on other pages.
Where do I put my sitemap in robots.txt?
Anywhere on the line, preceding it with “Sitemap:” followed by the full URL. You can list many sitemaps this way.
Can robots.txt have multiple user-agent blocks?
Yes. You can have as many as you want. You can also have a block that allows all crawlers using an asterisk.
Why is a page I disallowed still in Google?
Disallowing won’t prevent Google from crawling and possibly indexing the page. Use the noindex meta tag to prevent indexing.
Does robots.txt need to be lowercase?
The name of the file must be “robots.txt” exactly in lower case. The names of the directives in the file can be in any case. @CAP@URL paths have to be case sensitive.
How big can a robots.txt file be?
Google will read up to 500 KB of a robots.txt file. For most sites, the length of the file isn’t an issue.