Robots.txt is a plain text file at the root of your domain that tells search engine crawlers which URLs they may or may not crawl. It controls crawling, not indexing. A blocked page can still appear in search results if other sites link to it, so use a noindex tag when you need a page kept out of the index.
Key takeaways
- Robots.txt must sit at the root, such as example.com/robots.txt, and applies per host.
- Disallow stops crawling but does not guarantee removal from Google's index.
- Never block CSS or JavaScript files that Google needs to render pages.
- Test every change before publishing, because one wrong line can block a whole site.
How is a robots.txt file structured?
The file is made of groups. Each group starts with one or more User-agent lines naming the crawler, followed by Allow and Disallow rules. User-agent: * applies to all crawlers that do not have their own group. Paths are case-sensitive and match from the start of the URL path. You can also list your XML sitemap location anywhere in the file. Google ignores the crawl-delay directive, although some other search engines still read it.
Google supports two wildcards. An asterisk matches any sequence of characters and a dollar sign marks the end of a URL. When Allow and Disallow rules conflict, Google follows the most specific rule, meaning the one with the longest matching path.
- User-agent: names the crawler, such as Googlebot or *
- Disallow: a path the crawler should not fetch
- Allow: an exception inside a disallowed path
- Sitemap: the full URL of your XML sitemap
What does a sensible file look like?
For most small business sites, robots.txt should be short. Block only areas with no search value, such as admin panels, internal search results, cart and checkout steps, and URL parameters that create endless duplicates. Leave everything else open and list your sitemap.
An e-commerce site might add rules for sort and filter parameters it does not want crawled, while leaving a few valuable filtered category pages accessible. Write rules carefully so a pattern meant for parameters does not accidentally match real category URLs.
What is the difference between blocking and noindex?
This is the most misunderstood point. Disallow tells Google not to fetch a page. If the page is linked from elsewhere, Google may still index the URL and show it with little or no description. A noindex meta tag or X-Robots-Tag header tells Google not to show the page in results, but Google must be able to crawl the page to see that instruction.
So never combine the two on the same page if your aim is removal. Allow crawling, add noindex, wait for Google to recrawl and drop the page, then consider blocking it later if crawl waste is a concern. For urgent removals, use the Removals tool in Search Console alongside a permanent fix.
For genuinely private content, such as customer documents or patient records, neither method is enough. Protect those areas with login or server-level authentication. Robots.txt is publicly readable, so listing sensitive folders there can actually point curious people towards them. Under the Digital Personal Data Protection Act 2023, protecting personal data is a legal duty, not an SEO setting.
What mistakes cause the most damage?
The classic disaster is a staging site's 'Disallow: /' line going live with a launch. It blocks the entire site and rankings can fall quickly. Other common errors include blocking CSS and JavaScript folders, which stops Google rendering pages properly, and using robots.txt to hide private content, which it does not protect because the file itself is public.
Typos also matter. Disallow: /blog blocks /blog, /blog/ and /blogging-tips because matching starts from the path beginning. Use a trailing slash or a dollar sign when you mean something narrower. Also remember that rules are case-sensitive, so /Products/ and /products/ are different paths. Read every new line against a few real URLs before publishing.
How do you test and monitor robots.txt?
Search Console includes a robots.txt report under Settings that shows the version Google last fetched, when it was fetched and any parsing errors. Use URL Inspection to confirm whether a specific URL is blocked. A crawler such as Screaming Frog can also test your rules against a list of URLs before you publish changes.
Add robots.txt to your release checklist. After every deployment, open the live file and confirm it matches what you expect. Some teams set up a simple uptime monitor that alerts them if the file changes unexpectedly. This is cheap insurance, because a blocked site can lose a large share of organic traffic before anyone notices the cause.
Frequently asked questions
Does every website need a robots.txt file?
No. If the file is missing, crawlers assume they may crawl everything, which is fine for many small sites. A short file is still useful to list your sitemap and to block obvious low-value areas such as admin or internal search pages. An empty or missing file is far safer than a wrong one.
Can I block AI crawlers with robots.txt?
Many AI companies publish user-agent names and say they respect robots.txt, so you can add groups that disallow them. Compliance depends on each crawler. Weigh the decision carefully, as blocking some agents may affect whether your content appears in certain AI products. Google-Extended is a separate token from Googlebot.
Do subdomains need their own robots.txt?
Yes. Robots.txt applies only to the exact host and protocol where it sits. A file on www.example.in does not control blog.example.in or shop.example.in. Each subdomain needs its own file at its own root if you want rules to apply there.
