SEO guide

robots.txt guide: how do you write and test the right file?

robots.txt is a plain text file in your site's root directory that tells bots which URLs they may crawl. In this guide you'll learn what the file does and doesn't do, how its lines are written, how Google resolves conflicting rules, the most common mistakes, and how to test your file before you publish it.

12 min readUpdated: November 6, 2026

In short

  • robots.txt manages crawling, not indexing: a blocked URL that gets links from other sites can still appear in search results without a description.
  • To remove a page from Google, use noindex and leave the page open to crawling; Google hasn't applied Noindex lines in robots.txt since 2019.
  • Google applies the longest rule that matches the URL; if the lengths are equal, Allow wins. A bot reads only the group that names it.
  • If the file returns 404, everything can be crawled; if it returns 5xx or 429, Google temporarily stops crawling the site altogether.
  • Don't block CSS and JavaScript files; protect your test site with a password, not with robots.txt.

What does robots.txt do, and what doesn't it do?

When search engine bots arrive at a site, they first request /robots.txt and use this file to decide which URLs to crawl. The rules are based on the Robots Exclusion Protocol, which emerged in 1994 and was standardized in 2022 as RFC 9309. Google states plainly that the file's main purpose is to keep your server from being overloaded with unnecessary requests, and that it is not a way to keep a page out of Google.

What you can do with robots.txt:

  • Close off sections that generate an endless number of URLs: internal search results, sorting and filter parameters, calendar pages.
  • Reduce crawl requests to pages that are useless in search, such as the cart, checkout and account pages.
  • Keep image, video and audio files from appearing in Google's image and video results.
  • Tell bots where your sitemap is.

What you can't do:

  • Remove a page from the index. Google doesn't read the content of a blocked page, but if the URL gets links from other pages, Google can still show it in results without a description.
  • Hide content. The file is public; writing Disallow: /gizli-teklifler/ announces that folder's existence to everyone. Truly private content needs a password.
  • Stop malicious bots. robots.txt is a request: documented search bots comply, while scrapers and fake bots don't even look at the file. A hard block requires a server or CDN rule.

Where should the file live, and how should it be served?

Bots look for robots.txt only at the root of the host: https://www.ornek-site.com/robots.txt. The file applies only to the protocol, host and port where it lives; http://www.ornek-site.com, https://blog.ornek-site.com or https://www.ornek-site.com:8080 don't use it. If these addresses permanently redirect to the main version, Google follows the redirect for the robots.txt request too; if they're published as separate sites (such as a blog subdomain), each needs its own file at its root. Files in subfolders (/blog/robots.txt) aren't read, and the file name is written in lowercase.

According to Google's documentation, the file's HTTP response determines how the rules are interpreted:

  • 2xx: the file is read and the rules are applied.
  • 3xx: Google follows up to five redirects; if the chain is longer, it treats the file as a 404.
  • 4xx (except 429): including 401 and 403, Google acts as if the file doesn't exist, and the whole site counts as crawlable.
  • 5xx and 429: the site is treated as temporarily fully blocked. If the error lasts more than 30 days, Google uses the last cached copy; if there is none, it assumes there are no restrictions.

The file must be UTF-8 encoded plain text served as text/plain. Google reads only the first 500 KiB and ignores any rules after that. Because it generally caches the file for up to 24 hours, your changes may not take effect right away.

In single-page applications (SPAs), a rule that returns index.html for every unknown URL can also answer the /robots.txt request with an HTML page and a 200 code. Google finds no valid lines on that page and treats everything as crawlable; the rules you think you've written are never applied.

Syntax: User-agent, Disallow, Allow and Sitemap

The file is made up of groups. Each group starts with one or more User-agent lines and continues with the Disallow and Allow rules that apply to those bots. A typical file looks like this:

User-agent: *
Disallow: /sepet/
Disallow: /hesabim/
Disallow: /indirmeler/
Allow: /indirmeler/katalog.pdf

User-agent: Googlebot-Image
Disallow: /ozel-gorseller/

Sitemap: https://www.ornek-site.com/sitemap.xml
  • User-agent says which bot the rules apply to. * means every bot that has no group of its own. Bot names are case-insensitive.
  • Disallow gives the path you don't want crawled. The path is the part after the domain name and starts with /. A Disallow: with an empty value blocks nothing.
  • Allow opens a crawlable path inside a blocked section. Google and Bing support it, and it's part of RFC 9309.
  • Sitemap gives the full URL of your sitemap. It isn't tied to any group, can appear anywhere in the file and can be repeated; the sitemap can even be on another host.
  • Everything after # is a comment and is ignored.

Directive names are case-insensitive, but paths are case-sensitive: the rule Disallow: /Urunler/ doesn't block /urunler/. Google doesn't apply the Crawl-delay line and sets the crawl rate itself based on your server's responses; Yandex no longer takes it into account either, while Bing follows it.

Wildcards: * and $

Google and RFC 9309 recognize two special characters: * means zero or more of any character, and $ means the end of the URL. Matching starts at the beginning of the path and includes the query string (everything after ?):

  • The rule Disallow: /urun matches /urun, /urunler/, /urun-karsilastir and /urun.php?id=5; it doesn't match /kategori/urun.
  • Disallow: /urunler/ matches only URLs inside the folder, not /urunler itself.
  • Disallow: /*.pdf$ blocks every file whose name ends in .pdf; it doesn't match /katalog.pdf?v=2, because that URL doesn't end in .pdf.
  • Disallow: /*? blocks every URL that contains a question mark, that is, every URL with parameters.
  • A trailing * is redundant: /urun* and /urun mean the same thing.

How are groups formed?

Consecutive User-agent lines share the same group. In Google's interpretation, a group ends only when a new User-agent line follows its rules; a blank line, a comment or a Sitemap line doesn't split a group. That's why both bots are blocked from the whole site in the file below:

User-agent: GPTBot
Sitemap: https://www.ornek-site.com/sitemap.xml

User-agent: CCBot
Disallow: /

To avoid confusion, end each group with its own rules, put a blank line between groups and collect the Sitemap lines at the end of the file.

How does Google resolve conflicting rules?

The decision for a URL is made in two steps: first the group the bot will follow is chosen, then the most specific rule in that group that matches the URL is applied.

Which group applies?

Each bot follows the single group that names it most specifically and ignores the others; the order of groups in the file doesn't matter. Googlebot-Image, for example, first looks for its own group, then for the Googlebot group, and if neither exists, applies the * group. If there are several groups for the same bot, Google merges them, but it never merges the * group with a specific bot's group.

This is where the most common mistake comes from: once you write a separate group for Googlebot, the rules in the * group no longer apply to Googlebot.

User-agent: *
Disallow: /sepet/
Disallow: /hesabim/

User-agent: Googlebot
Disallow: /deneme/

In this file, Googlebot can crawl the /sepet/ and /hesabim/ folders, because it reads only its own group. If you want the general rules to apply to Googlebot as well, write them into the Googlebot group too.

Which rule wins?

Among the rules that match a URL, Google applies the one with the longest path; wildcards count toward the length too. If the lengths are equal, the least restrictive rule, that is Allow, wins. The order of rules within a group doesn't matter to Google. Examples:

  • With Allow: /urunler/indirim and Disallow: /urunler/, the URL /urunler/indirim is crawled, because the Allow rule is longer.
  • With Allow: /klasor and Disallow: /klasor, the URL /klasor/sayfa is crawled: the lengths are equal, so Allow wins.
  • With Allow: /urun and Disallow: /*.htm, the URL /urun.htm is not crawled: the wildcard rule, at six characters, is longer than the Allow rule (five characters).
  • If Allow: /$ and Disallow: / appear together, only the home page is crawled and no other URL is.
  • With Allow: /*?sayfa= and Disallow: /*?, the URL /kategori?renk=mavi&sayfa=2 is not crawled: because sayfa= doesn't come right after the question mark, the Allow rule doesn't match this URL.

The last example is a common trap with parameterized URLs: when the order of the parameters changes, so does the result. For a rule that works wherever the parameter appears, write /*sayfa=. Some older parsers apply the first matching rule instead, so putting Allow lines above the related Disallow line is a harmless precaution.

See on one screen which bots can access a URL and which line matches it.

robots.txt tester

The most common robots.txt mistakes

Blocking CSS and JavaScript files

Google renders pages the way a browser does. If you block the CSS and JavaScript files needed for the layout, it sees an incomplete page, and its assessment of mobile-friendliness and content suffers. Leftover lines from old templates such as Disallow: /wp-includes/, Disallow: /assets/ or Disallow: /*.js$ are the most common cause.

The cleanest fix is to delete the line. If you need to keep the folder closed, take the precedence rule into account: the five-character Allow: /*.js can't beat the thirteen-character Disallow: /wp-includes/. The allowing rule must be at least as long as the blocking one:

User-agent: *
Disallow: /wp-includes/
Allow: /wp-includes/*.css
Allow: /wp-includes/*.js

For files served with a version parameter (style.css?v=3), don't end the rule with $; if you do, the URL won't match the rule.

The test site's robots.txt ends up in production

A Disallow: / line written to close off a development or test site can make its way to the live site with a deployment; within a few days the site starts dropping out of search. The risk runs the other way too: robots.txt doesn't stop the test site from being indexed, and test URLs that have been shared somewhere can show up in results.

Protect test environments with HTTP authentication, not with robots.txt. In Nginx:

location / {
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/.htpasswd;
}

Check the live site's robots.txt as part of your deployment process too. The command below prints any lines that close off the whole site, with their line numbers; if such a line is in the * or Googlebot group, the site is closed to search:

curl -s https://www.ornek-site.com/robots.txt | tr -d '\r' | grep -inE '^disallow:[[:space:]]*/[[:space:]]*$'

If you use WordPress, also check the search engine visibility box under Settings › Reading: today this setting writes a noindex tag into your pages rather than into robots.txt, and if it's forgotten at launch, the result is the same.

Blocking pages you want removed from the index

Adding a page to robots.txt to remove it from search is the most common wrong move. Because Google can no longer crawl the page, it can't see the noindex tag on it either; the URL can remain in the index without its content. The right order is:

  1. If you're blocking the page in robots.txt, remove the block.
  2. Add <meta name="robots" content="noindex"> to the page, or send the X-Robots-Tag: noindex header from the server. If the page has been removed entirely, returning 404 or 410 is enough too.
  3. Use the URL Inspection tool in Search Console to request a recrawl of the URL, and wait for the page to drop out of the index.
  4. Leave the page with its noindex in place. If you block it again, Google will never see the noindex again.

In an emergency, Search Console's Removals tool hides the page from results for about six months; the permanent fix is still noindex, 404 or 410.

Mixing up the trailing slash and letter case

The rule Disallow: /admin blocks /admin, /admin/ and /admin-paneli, and even the /administrator page. Disallow: /admin/, by contrast, blocks only what's inside the folder. Because paths are case-sensitive, write URLs exactly as they appear on your site; on campaign pages, /Kampanya and /kampanya are two different paths.

Unsupported lines and typos

Since September 1, 2019, Google hasn't applied Noindex, Nofollow and similar lines in robots.txt; Host and Clean-param are specific to Yandex. Writing a full URL in a Disallow line (Disallow: https://www.ornek-site.com/sepet/) makes the rule useless, because a rule expects a path; the Sitemap line, by contrast, requires a full URL. Google tolerates some common typos such as Dissallow, but Bing and other bots may ignore the same line.

Robots meta tag and X-Robots-Tag: managing the index

Indexing is controlled not by robots.txt but by page-level directives. On HTML pages, a meta tag goes inside <head>:

<meta name="robots" content="noindex, follow">
<meta name="googlebot" content="nosnippet">

The name robots addresses all bots; googlebot addresses Google only. The most widely used values: noindex (don't show the page in results), nofollow (don't follow the links on the page), none (both), nosnippet and max-snippet (the text preview in results), max-image-preview:large (large image preview). For details, see the meta tags guide.

For PDFs, images and other non-HTML files, give the same directives with the X-Robots-Tag header in the HTTP response. In Apache:

<Files ~ "\.pdf$">
  Header set X-Robots-Tag "noindex"
</Files>

In Nginx:

location ~* \.pdf$ {
    add_header X-Robots-Tag "noindex";
}

Here's a quick way to decide which one to use when:

  • If you don't want a URL crawled (server load, endless filter URLs): robots.txt.
  • If you don't want a URL to appear in results: noindex on a page that's open to crawling.
  • If you don't want anyone to see the content: a password or a login.
  • If the same content has several URLs: a canonical tag, not robots.txt.

To see the meta tags and headers of a page together, use the Meta tag checker; for the response headers alone, use the HTTP header checker.

How do you manage AI bots in robots.txt?

AI companies' bots also check robots.txt, and most use separate names depending on their purpose. Bots that collect content for model training (such as GPTBot, ClaudeBot and CCBot) are independent of bots that cite sources in AI search (such as OAI-SearchBot, Claude-SearchBot and PerplexityBot). A site that only wants to opt out of training could write:

User-agent: GPTBot
User-agent: ClaudeBot
User-agent: CCBot
User-agent: Google-Extended
Disallow: /

User-agent: *
Disallow: /sepet/

The group rule applies here too: when you write a separate group for AI bots, the rules in the * group no longer apply to them. Google-Extended isn't a crawler but a token that controls Gemini training; it doesn't affect Google Search or AI Overviews. You can see what each bot does and the pros and cons of blocking in the AI bots guide, and your site's current status in the AI bot access checker.

Ready-made examples: WordPress, e-commerce and a closed site

WordPress

If there's no real file in the root directory, WordPress generates a virtual robots.txt; if the built-in sitemap is enabled, it declares that too:

User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php

Sitemap: https://www.ornek-site.com/wp-sitemap.xml

This file is enough for most sites. The admin-ajax.php exception exists because some themes and plugins load page content through that address. If you upload a real robots.txt file to the root directory, the virtual file is switched off and you have to write the Sitemap line yourself.

E-commerce site

User-agent: *
Disallow: /sepet/
Disallow: /odeme/
Disallow: /hesabim/
Disallow: /arama?
Disallow: /*siralama=
Disallow: /*fiyat=

Sitemap: https://www.magaza-ornek.com/sitemap.xml

Cart, checkout and account pages are useless in search, while internal search and sorting parameters generate an unlimited number of URLs. Don't close off category filters blindly: a filter combination people search for, such as "red dress", may deserve its own page. Block only the parameters with no search value, and handle the others that create duplicate content with a canonical tag.

A site that isn't ready to launch

User-agent: *
Disallow: /

These two lines keep all bots away from the entire site, but they don't remove the site from the index or hide it. Use them only as a short-term measure, and put removing them on your launch checklist.

Start from a template, make your choice for AI bots and see mistakes as you type.

robots.txt generator

How do you test robots.txt step by step?

  1. Prepare the file. In the robots.txt generator, start from the WordPress, e-commerce or Shopify template and add your own rules. As you type, the tool flags rules that close the site to search engines, block CSS and JavaScript files or are written incorrectly; the file is built in your browser.
  2. Try it before publishing. Paste the file into the "Paste robots.txt" tab of the robots.txt tester; no request is sent to the site. Test one URL from each template for Googlebot: the home page, a category, a product or post, a CSS file, a filter URL with parameters and a page you want to block. For each URL, the tool shows the matching line and the group that applies.
  3. Upload the file to the root directory and open https://www.ornek-site.com/robots.txt in your browser to confirm it shows up as plain text.
  4. Check the live file. Test your domain in the tester's "Live site" tab. The HTTP status code, content type, size, redirects, typos and the access of 24 bots to that URL all appear on one screen. The "Edit and test" button moves the live file to the paste tab, where you can try out your change.
  5. Let Google know. The robots.txt report in Search Console's settings shows when Google last read your file and any problems it found; after an urgent fix, you can request a recrawl of the file there. For a single URL, the URL Inspection tool tells you whether crawling is allowed.
  6. Monitor the results. A few days later, review the URLs blocked by robots.txt in Search Console's Page indexing report; if a page is on that list that shouldn't be, fix the rule.

Pre-launch checklist

  • The file is at the root and returns a 200 code with the text/plain type; it's smaller than 500 KiB.
  • The * and Googlebot groups don't block the home page or important templates.
  • CSS, JavaScript and image files can be crawled.
  • Pages you want out of the index are marked with noindex, not listed in robots.txt.
  • For bots with their own group, the general rules have been written into those groups too.
  • The Sitemap line contains a full URL and the sitemap opens.
  • The test environment is password-protected, and its robots.txt isn't carried over to the live site.

Frequently asked questions

Is a robots.txt file required?

No. If there's no file and the server returns 404, bots treat the whole site as crawlable. Still, publishing a short file to declare your sitemap and close off unnecessary URLs such as the cart and internal search is a good habit.

Why does a page I blocked with Disallow still show up in Google?

Because Disallow blocks crawling, not indexing. If Google knows the URL from links on other sites, it can show it without reading its content and without a description. To remove the page, lift the block and add noindex to the page.

Does the order of rules in robots.txt matter?

Not for Google: the longest rule that matches the URL wins, and if the lengths are equal, Allow applies; the order of groups doesn't change the result either. Because some older bots apply the first matching rule, putting Allow lines above the related Disallow line is a harmless precaution.

Can I use wildcards in robots.txt?

Yes. Google, Bing and RFC 9309 support two wildcards: the asterisk (*) means any sequence of characters and the dollar sign ($) means the end of the URL. Wildcards aren't used in bot names, though; only an asterisk written on its own covers all bots.

Does Crawl-delay work in Google?

No. Google ignores the Crawl-delay line and sets the crawl rate itself based on your server's responses. If you urgently need to slow crawling down, Google recommends returning 500, 503 or 429 for a few hours or a day or two. Bing follows Crawl-delay; Yandex no longer takes it into account.

Do I need a separate robots.txt for my subdomain?

Yes. robots.txt applies only to the protocol, host and port where it lives. A blog subdomain doesn't use the main site's file; every subdomain published separately needs its own robots.txt file at its root.

Related guides and tools