What robots.txt does
robots.txt sits at the root of your domain (https://example.com/robots.txt) and tells crawlers which parts of the site they may request. Reputable search engines and many other bots read it before crawling. It is a set of requests, not security: anything sensitive should be behind a login, not just listed in robots.txt.
The basic syntax
A file is made of groups. Each group starts with one or more User-agent lines, followed by rules:
User-agent: * Disallow: /admin/ Allow: /admin/help/ Sitemap: https://example.com/sitemap.xml
User-agent: *applies to every crawler that has no group of its own. A named group such asUser-agent: Googlebotapplies only to that crawler.Disallow: /path/asks the crawler not to fetch URLs starting with that path. An emptyDisallow:allows everything.Allow:makes an exception inside a disallowed folder. For Google, the most specific (longest) matching rule wins.*matches any sequence of characters and$marks the end of a URL, soDisallow: /*.pdf$blocks PDF files. Google and Bing support these.Sitemap:gives the full URL of your sitemap and can appear anywhere in the file.
Paths are case-sensitive, and each rule needs its own line.
Ready-made examples
Allow everything, point to the sitemap
User-agent: * Disallow: Sitemap: https://example.com/sitemap.xml
WordPress
User-agent: * Disallow: /wp-admin/ Allow: /wp-admin/admin-ajax.php Sitemap: https://example.com/wp-sitemap.xml
Ask AI crawlers not to crawl
User-agent: GPTBot Disallow: / User-agent: ClaudeBot Disallow: / User-agent: CCBot Disallow: /
The robots.txt generator has these as presets, with a longer, editable list of AI user-agents.
Mistakes that cost traffic
Disallow: /left over from a staging site. It blocks your whole site. Check robots.txt after every launch.- Blocking CSS, JavaScript or image folders. Search engines need them to render the page as visitors see it.
- Using robots.txt to remove pages from Google. A blocked URL can still be indexed from links, without a description. To keep a page out, allow crawling and add a
noindextag. - Relative sitemap paths. The Sitemap line needs a full URL.
robots.txt vs noindex vs passwords
These three are often confused, and each does a different job. robots.txt controls crawling: whether a bot fetches a URL at all. noindex, set in a meta tag or HTTP header, controls indexing: whether a page that has been crawled may appear in results. For noindex to work the page must not be blocked in robots.txt, because the crawler has to fetch the page to see the tag. Passwords or other access controls are the only real way to keep content private, since robots.txt itself is public and anyone can read the paths you list in it.
Uploading and testing
- Save the file as plain text named exactly
robots.txt. - Upload it to the root of the domain, using your host's file manager, FTP, or your CMS or SEO plugin's editor.
- Open
yoursite.com/robots.txtin a browser to confirm it is live. - In Google Search Console, the robots.txt report shows whether Google fetched the file and flags problems it found.
Then make sure the sitemap it points to exists; our guide on creating an XML sitemap covers that.