Robots.txt Explained With Examples

A beginner-friendly robots.txt guide with copy-paste examples, a pre-launch checklist and the one mistake that can quietly wipe a site out of Google.

One tiny text file can stop Google from crawling your entire website.

Most freshers have never opened it. Many of the ones who have copy a snippet from a blog and hope for the best.

This robots.txt guide fixes that. You will learn what the file does, how to write it, how to test it, and where people break things.

What robots.txt actually does

Robots.txt is a plain text file that sits at the root of your domain, for example example.com/robots.txt. It tells crawlers (bots like Googlebot) which URLs they may request and which they should stay away from.

Two things to burn into your memory:

  • It controls crawling, not indexing. A blocked URL can still appear in Google if other pages link to it.
  • It is a request, not a lock. Google and Bing respect it. Bad bots ignore it. Never use it to hide private data.

If crawling and indexing still feel like the same thing, my 5-layer SEO pyramid explains where each one sits. Crawlability is the base layer, and everything else depends on it.

The syntax in 5 minutes

A robots.txt file is made of groups. Each group starts with a user-agent (which bot) and then lists rules.

Here are the directives you will use 95% of the time:

Directive What it does Example
User-agent Names the bot the rules apply to. * means all bots. User-agent: Googlebot
Disallow Blocks a path from being crawled. Disallow: /cart/
Allow Makes an exception inside a blocked path. Allow: /cart/help/
Sitemap Points bots to your XML sitemap. Needs a full URL. Sitemap: https://example.com/sitemap.xml
* (wildcard) Matches any sequence of characters. Disallow: /*?sort=
$ (end marker) Matches the end of a URL. Disallow: /*.pdf$

Paths are case-sensitive. /Cart/ and /cart/ are different things. Also, Google ignores the Crawl-delay directive, so do not waste time on it for Google.

Robots.txt examples you can adapt

All domains below are examples. Replace them with your own.

Example 1: Allow everything (the safe default)

  • User-agent: *
  • Disallow:
  • Sitemap: https://example.com/sitemap.xml

An empty Disallow means nothing is blocked. For a small blog or portfolio site, this is often all you need.

Example 2: Block an eCommerce site’s low-value URLs

  • User-agent: *
  • Disallow: /cart/
  • Disallow: /checkout/
  • Disallow: /my-account/
  • Disallow: /*?sort=
  • Disallow: /*?filter=
  • Sitemap: https://example.com/sitemap.xml

Cart, checkout and account pages have no search value. Sorting and filter parameters can create thousands of near-duplicate URLs that waste crawl budget (the number of URLs Google is willing to crawl on your site in a given period).

Example 3: Block a folder but allow one file inside it

  • User-agent: *
  • Disallow: /downloads/
  • Allow: /downloads/brochure.pdf

The more specific rule wins. That is why the Allow works here.

Example 4: Block the whole site (staging only)

  • User-agent: *
  • Disallow: /

That single slash means “everything”. This is correct for a staging or test site. It is a disaster on a live site.

Example 5: Different rules for different bots

  • User-agent: Googlebot
  • Disallow: /internal-search/
  •  
  • User-agent: GPTBot
  • Disallow: /

A bot follows the most specific group that matches its name. Whether to block AI crawlers is a business decision, so check with the site owner before you do it.

A mistake I see freshers make

A fresher wants a thin or duplicate page out of Google. They add a Disallow rule for it and report “done”.

Here’s the thing: that often makes it worse. Google can no longer crawl the page, so it never sees a noindex tag on it. If the URL has links pointing to it, it can stay in the index as a bare result with no description.

The correct order is:

  1. Add a noindex meta tag to the page and leave it crawlable.
  2. Wait until Google recrawls it and the page drops out of the index.
  3. Only then, if you really need to, block the path in robots.txt.

Also, noindex inside robots.txt itself has not been supported by Google for years. Do not use it. I cover more habits like this in SEO mistakes beginners make in their first job.

The migration moment that taught me to check first

On client sites during redesigns and migrations, I have seen a staging robots.txt (with Disallow: /) go live along with the new design. Nobody did it on purpose. It was simply part of the files that got moved.

That is why I now open yourdomain.com/robots.txt on launch day before I check anything else. It takes ten seconds. It has saved me a lot of awkward calls.

How to test your robots.txt step by step

Do not publish a change and hope. Use this process.

  1. Open the file in your browser. Go to yourdomain.com/robots.txt. It should load as plain text.
  2. Check the status code. It should return 200. Run it through the HTTP Status Checker. A 404 means “no rules, crawl everything”. Server errors (5xx) can make Google back off crawling your whole site.
  3. Check for redirects. Use the Redirect Checker. A clean robots.txt should not bounce through multiple hops. Also check that http, https, www and non-www versions all resolve to the same final file.
  4. Validate your rules. Paste the file into the Robots.txt Checker and test the exact URLs you care about.
  5. Check what Google sees. In Search Console, go to Settings > Crawling > robots.txt > Open report. You can see the file Google fetched, when it fetched it and any parsing errors. You can also request a recrawl there after an urgent fix.
  6. Test a live URL. Paste an important URL into the top search bar in Search Console to open URL Inspection. Look at Page indexing and check for “Blocked by robots.txt”. Under the live test, Crawl allowed? should say Yes.
  7. Look at the real crawl behaviour. If you have server logs, upload them to the Log File Analyzer and see whether Googlebot is still hitting URLs you thought you blocked, or wasting time on parameters.

Robots.txt pre-launch checklist

Copy this into your project notes.

  • File lives at the root: /robots.txt on the exact host (www or non-www) that is live.
  • Returns a 200 status, not a redirect chain or an error.
  • No “Disallow: /” on the live site.
  • CSS and JavaScript folders are not blocked. Google needs them to render pages.
  • Important sections (products, blog, category pages) are not caught by a broad pattern like /*? or /p.
  • Sitemap line is present with a full absolute URL.
  • Rules for cart, checkout, internal search and filters are intentional, not copied blindly.
  • Every Disallow has a reason you can explain in one line.
  • File was tested in the Robots.txt Checker and Search Console after any change.
  • A dated copy of the old file is saved, so you can roll back.

Common questions beginners ask

Do I need a robots.txt file at all?

No. Without one, bots assume they can crawl everything. But having one with a Sitemap line is good practice, and you need it as soon as the site has junk URLs to keep out.

Can I use robots.txt to protect private pages?

No. The file is public. Anyone can read it, and listing a private folder there actually advertises it. Use password protection or proper authentication.

Does a Disallow rule remove a page from Google?

No. It only stops crawling. Use noindex, a 404/410 status, or the removals tool depending on the situation.

How often does Google read the file?

Google caches it and refreshes it regularly, often within a day. That is why a fix can take a little while to show up, and why the Search Console report is worth checking.

What to do next

Pick any website, your own or a friend’s small business, and audit its robots.txt using the 7 steps above. Write down what is blocked, why, and whether you agree. That one exercise is a great portfolio note and a strong answer in interviews. Try it against the beginner SEO interview questions, which often include this topic.

To see where this fits in a full workflow, read Your SEO Process. If you get stuck on a real file, bring it to the free WhatsApp community and ask. Or write to hello@pranavsolanki.digital.

This article is based on my own work on client and in-house SEO projects since 2011. If something here doesn't match what you see on your site, write to me. I update posts when things change.