robots.txt: The Bouncer at Your Website's Door
robots.txt is a plain text file at your site's root that tells search engine crawlers which pages they can and can't access. It's not a security mechanism — it's a polite request that well-behaved bots honor.
Basic Syntax
# Allow everything (default if no robots.txt exists)
User-agent: *
Allow: /
# Block everything (hide site from search engines)
User-agent: *
Disallow: /
# Block specific paths
User-agent: *
Disallow: /admin/
Disallow: /api/
Disallow: /private/
Disallow: /tmp/
# Reference your sitemap
Sitemap: https://example.com/sitemap.xmlCommon Rules
# Block all bots from admin area
User-agent: *
Disallow: /admin/
Disallow: /dashboard/
Disallow: /api/
Disallow: /_next/ # Next.js internals
Disallow: /search? # search result pages (duplicate content)
# Allow specific bot access to everything
User-agent: Googlebot
Allow: /
# Block specific bad bots
User-agent: AhrefsBot
Disallow: /
User-agent: SemrushBot
Disallow: /
# Sitemap location
Sitemap: https://example.com/sitemap.xmlPattern Matching
# Block all PDF files
Disallow: /*.pdf$
# Block URLs with query parameters
Disallow: /*?*
# Block specific file types
Disallow: /*.json$
Disallow: /*.xml$Common Mistakes
| Mistake | Problem |
|---|---|
| Using robots.txt as security | It's public and advisory — anyone can ignore it |
Disallow: / in production | Blocks ALL crawling — site disappears from Google |
| Blocking CSS/JS files | Google can't render your page, hurts rankings |
| No Sitemap reference | Missed opportunity to tell crawlers about all your pages |
Blocking /images/ | Images won't appear in Google Image Search |
Testing
Google Search Console has a robots.txt tester. Or check manually:
curl https://example.com/robots.txtGenerate yours: robots.txt Generator — select your rules, get a ready-to-use robots.txt file.