What Is a Robots.txt File?
A robots.txt file is a set of rules that tells web crawlers which pages or sections of a website they should crawl and which to avoid.Â
It looks like this:

Robots.txt files may look complicated.Â
But the syntax (computer language) is straightforwardââAllowâ means the web crawler should crawl it, while âdisallowâ means the crawler should not crawl it.
But keep in mind:
While robots.txt guides crawler behavior, it doesnât guarantee that a page wonât appear in search results. Other factors (like external links) can still cause it to be indexed by Google.
To block indexing, you should use Meta Robots and X-Robots-Tag.
Robots.txt vs. Meta Robots vs. X-Robots
Robots.txt tells search engines what not to crawlâmeta robots tags and s-tobots-tags tell them what not to index.Â
Knowing the difference helps you apply the right tool for the right situation.
Hereâs how they compare:
- Robots.txt: This file is located in the websiteâs root directory and provides site-wide instructions to search engine crawlers on which areas of the site they should and shouldnât crawl
- Meta robots tags: These tags are snippets of code in the <head> sections of individual webpages and provide page-specific instructions to search engines on whether to index (include in search results) and follow (crawl the links on) each page
- X-robot tags: These code snippets are used primarily for non-HTML files (like PDFs and images) and are implemented in the fileâs HTTP header
If you want to keep something out of search results, use a noindex meta tag (on a crawlable page) or password-protect the page.
Why Does Robots.txt Matter?
A robots.txt file helps control how bots interact with your site.Â
SEOs often use it to manage crawl load and improve efficiency by blocking unimportant or duplicate pages. It can also be used to deter scraping and prevent content from being used to train AI models.
Hereâs a breakdown of why robots.txt files matter specifically for SEO:
It Optimizes Your Crawl Budget
A robots.txt file helps search engines focus their crawl budgets on your most valuable pages.
Blocking low-value pages (like cart, login, or filter pages) helps bots prioritize crawling content that actually drives traffic and rankings, especially on large sites with thousands of URLs.
For example:Â
Blocking â/cart/â or â/login/â pages helps bots focus on your blog posts or product pages instead.
It Can Be Used to Control Search Appearance
Robots.txt gives you some control over how your site appears in search by managing what gets crawled.
While it doesn't directly affect indexing, it works with the below to guide search engines toward your important content:
- Sitemap: A file that lists the important pages on your site to help search engines discover and crawl them more efficiently
- Canonical tags: An HTML tag that tells search engines which version of a page is the preferred one to index when duplicate or similar content exists
- Noindex directives: A signal (via a meta tag or HTTP header) that tells search engines not to include a specific page or pages in the index used for search results
It Helps Deter Scrapers and Unwanted Bots
Robots.txt is the first line of defense against unwanted crawlers, such as scrapers or bots harvesting content for training AI models.
For example, many sites now disallow AI botsâ user-agents via robots.txt.Â
This sends a clear signal to bots that respect the protocol and helps reduce server load from non-essential crawlers.
We partnered with SEO Consultant Bill Widmer to run a quick experiment and demonstrate how robots.txt rules impact crawler behavior in real-world conditions.
Hereâs what happened:
Bill had a rule in his robots.txt file blocking a number of crawlers.Â
He used Semrushâs Site Audit tool to crawl the entire site, setting the crawl limit high enough to catch all live pages.
But his website wasnât crawled due to the robots.txt directives.

After adjusting the robots.txt file, he ran the crawl again.Â
This time, his website was successfully crawled and included in the report.

How to Create a Robots.txt File
A robots.txt file is easy to createâdecide what to block, write your rules in a text file, and upload it to your siteâs root directory.
Just follow these steps:
1. Decide What to Control
Identify which parts of your site should or shouldnât be crawled.Â
Consider blocking:
- Login and user account pages (e.g., /login/) that donât offer public value and can waste crawl budget
- Cart and checkout pages (e.g., /cart/) you donât want in search results
- Thank-you pages or form submission confirmation screens (e.g., /thank-you/) that arenât useful to searchers
If youâre unsure, itâs best to err on the side of allowing rather than disallowing.Â
Incorrect disallow rules can cause search engines to miss important content or fail to render your pages correctly.
2. Target Specific Bots (Optional)
You can write rules for all bots (User-agent: *) or target specific ones like Googlebot (User-agent: Googlebot) or Bingbot (User-agent: Bingbot), depending on your specific needs.
Here are two situations when this makes sense:
- Controlling aggressive or less important bots: Some bots crawl frequently and can put an unnecessary load on your server. You might want to limit or block these types of bots.
- Blocking AI crawlers used for training generative models: If you donât want your content included in the training data for tools like ChatGPT or other LLMs, you can block their crawlers (e.g., GPTBot) in your robots.txt file.
3. Create a Robots.txt File and Add Directives
Use a simple text editor like Notepad (Windows) or TextEdit (Mac) to create your file and save it as ârobots.txt.âÂ
In this file, youâll add your directivesâthe syntax that tells search engine crawlers which parts of your site they should and shouldnât access.
A robots.txt file contains one or more groups of directives, and each group includes multiple lines of instructions.
Each group starts with a user-agent and specifies:
- Which user-agent(s) the group applies to
- Which directories (pages) or files the user-agent(s) should access
- Which directories or files the user-agent(s) shouldnât access
Optionally, include a sitemap to tell search engines which pages and files are most important. Just donât forget to submit your sitemap directly in Google Search Console.
Imagine you donât want Google to crawl your â/clients/â directory because it's primarily for internal use and doesn't provide value for searchers.
The first group in your file would look like this block:
User-agent:Â Googlebot
Disallow:Â /clients/You can add more instructions for Google after that, like this:
User-agent:Â Googlebot
Disallow:Â /clients/
Disallow:Â /not-for-googleThen press enter twice to start a new group of directives.Â
For example, to prevent access to â/archive/â and â/support/â directories for all search engines.
Hereâs a block preventing access to those directories:
User-agent:Â *
Disallow:Â /archive/
Disallow:Â /support/Once youâre finished, add your sitemap:
User-agent:Â Googlebot
Disallow:Â /clients/
Disallow:Â /not-for-google
User-agent:Â *
Disallow:Â /archive/
Disallow:Â /support/
Sitemap:Â https://www.yourwebsite.com/sitemap.xmlFeeling unsure?Â
Use a free robots.txt generator to help you generate the text for your robots.txt file. Then, copy and paste the output to a text editor.Â

4. Upload the File to Your Siteâs Root Directory
Search engines will only read your robots.txt file if itâs placed in the root directory of your domain.
This means the file must be at the top level of your siteânot in a subfolder.Â
To upload the file correctly, use your web hosting file manager, FTP client, or CMS settings to upload the file to the root directory (usually called âpublic_htmlâ or â/wwwâ).
If you're using WordPress, you can use a plugin like Yoast SEO or Rank Math to upload the file to your siteâs root directory for you.Â
Just open the pluginâs settings, navigate to the robots.txt option, and upload your file.

5. Confirm the File Was Uploaded Successfully
Use Googleâs robots.txt report in Search Console to check for errors and confirm your rules work as intended.Â
In Search Console, navigate to the âSettingsâ page and click âOpen Reportâ next to ârobots.txt.â

It should have a green checkmark next to âFetchedâ under the status column.
But if there was an error, youâll see a red exclamation mark next to âNot Fetched.â In that case, check Googleâs guidelines to determine what the error was and how to fix it.
It can be difficult to understand Googleâs solutions to errors if youâre new to robots.txt.
If you want an easier way, run a free SEO check for a quick robots.txt review on your site.
For a deeper, site-wide analysis with detailed fix instructions, use the Semrush Site Audit tool.
Set up a project and run an audit.
When the tool is ready, navigate to the âIssuesâ tab and search for ârobots.txt.â

Click âRobots.txt file has format errorsâ if it appears.

View the list of invalid lines to determine exactly what needs to be addressed.

Check your robots.txt file regularly. Even small errors can affect your siteâs indexability.
Robots.txt Best Practices
Follow these best practices to ensure your robots.txt file helps your SEO and site performance:
Use Wildcards Carefully
Wildcards (* and $) let you match broad patterns in URLs, and using them precisely is important to avoid accidentally blocking important pages.
- * matches any sequence of characters, including slashes. Itâs used to block multiple URLs that share a pattern. (Example: âDisallow: /search*â blocks â/search,â â/search?q=shoes,â and â/search/results/page/2.â)
- $ matches the end of a URL. Itâs used when you want to block only URLs that end in a specific way. (Example: âDisallow: /thank-you$â blocks â/thank-youâ but not /thank-you/page.)
Here are some examples of how not to use them:
Disallow: /*.php blocks every URL ending in â.php,â which could include important pages like â/product.phpâ or â/blog-post.phpâ
Disallow: /.html$ blocks all pages ending in â.html,â which might include all your main site content
If youâre unsure, itâs wise to consult a professional before using wildcards in your robots.txt file.
Avoid Blocking Important Resources
Donât block CSS, JavaScript, or API endpoints required to render your site. Google needs them to understand layout, functionality, and mobile-readiness.
So, let crawlers access:
- /assets/
- /js/
- /css/
- /api/
Blocking these could cause Google to see a broken version of your pages and hurt your rankings.
Always test your site in Googleâs URL Inspection Tool to ensure blocked assets arenât interfering with rendering.Â
Enter a URL you want to test.Â
You should see a green checkmark if itâs done properly. If you see âBlocked by robots.txt,â the page (or an asset it depends on) is blocked from crawling.

Donât Use Robots.txt to Keep Pages Out of Search Results
If a URL is linked from elsewhere, Google can still index it and show it in search resultsâeven if youâve disallowed it in robots.txt.
That means you shouldnât rely on robots.txt to hide:
- Sensitive or private data (e.g., admin dashboards, internal reports)
- Duplicate content (e.g., filtered or paginated URLs)
- Staging or test sites
- Any page you donât want appearing in Google
Add Comments
Use comments to document your rules, so others (or future you) can understand your intentions.
Start a comment by adding a â#â. Anything after it on the same line will be ignored by crawlers.
For example:
# Block internal search results but allow all other pages for all crawlers
User-agent:Â *
Disallow:Â /search/
Allow:Â /Comments are especially important for growing teams and complex sites.
Robots.txt and AI: Should You Block LLMs?
AI tools like ChatGPT and those built on other large language models (LLMs) are trained on web contentâand your robots.txt file is the primary way for you to manage how they crawl your site.
To allow or block AI crawlers used to train models, add user-agent directives to your robots.txt file just like you would for Googlebot.Â
For example, OpenAIâs GPTBot is used to collect publicly available data that can be used for training large language models. To block it, you can include a line like âUser-agent: GPTBotâ followed by your chosen disallow rule.
When should you allow or block AI crawlers?
You should allow AI crawlers if:
- You want to increase exposure and don't mind your content being used in generative tools
- You believe the benefits of increased visibility and brand awareness outweigh control over how your content is used to train generative AI tools
You should consider blocking AI crawlers if:
- Youâre concerned about your intellectual propertyÂ
- You want to maintain full control over how your content is used
Note that a new file called llms.txt is being proposed to help AI models understand what your site is about and what content is most important. But it's not exactly a translation of robots.txt for AI models.Â
We wanted to see how many .com websites have an llms.txt file to see how commonly used this new file type is.
This rough experiment shows that only ~2,830 of .com websites indexed in Google have an llms.txt file.Â

As new updates come out, llms.txt files may become more important. Only time will tell.
Check Your Website for Robots.txt and Other Technical Issues
A well-configured robots.txt file is a powerful tool for guiding search engines, protecting your resources, and keeping your site efficient.Â
But itâs important to ensure your file is free from technical errors.
Use our free SEO checker to automatically look for robots.txt errors, crawl issues, broken links, and other technical SEO issues.
