seolivly
Robots.txt guide

How to Write a Robots.txt File

robots.txt is a short text file with a lot of power. A few lines guide crawlers well; one wrong line can hide a site from search.

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 as User-agent: Googlebot applies only to that crawler.
  • Disallow: /path/ asks the crawler not to fetch URLs starting with that path. An empty Disallow: 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, so Disallow: /*.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 noindex tag.
  • 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

  1. Save the file as plain text named exactly robots.txt.
  2. Upload it to the root of the domain, using your host's file manager, FTP, or your CMS or SEO plugin's editor.
  3. Open yoursite.com/robots.txt in a browser to confirm it is live.
  4. 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.

Frequently asked questions

Where do I put my robots.txt file?

In the root of your domain so it loads at https://yoursite.com/robots.txt. Subdomains need their own file.

Do I need a robots.txt file?

It is optional. Without one, crawlers assume everything is allowed. A simple file with a Sitemap line is still useful.

Does robots.txt block pages from Google search?

It blocks crawling, not indexing. Use a noindex tag on a crawlable page to keep it out of results.

Can I block AI bots with robots.txt?

You can ask them not to crawl by naming their user-agents. Reputable AI crawlers say they respect it; it is not enforcement.

Is robots.txt case-sensitive?

Paths are case-sensitive. The directive names such as Disallow are not, but writing them in the standard form is clearest.

Keep going