Skip to content
ExponaBLOG
TECHNICAL SEO FOR DEVELOPERS · DAY 006 / 100

robots.txt deep dive: a Technical SEO guide for developers

A tiny file with the power to hide your entire site.

Expona Admin6 min read

A robots.txt deep dive reveals one of the most misunderstood files in web development. It's tiny, often forgotten, and yet has the power to hide your entire site from search engines—sometimes by accident. Understanding how it actually works, what it controls, and what it doesn't control is critical for anyone running production platforms.

What robots.txt actually controls—and doesn't

The most common misconception is that robots.txt prevents indexing. It doesn't. robots.txt controls crawling only. A URL blocked in robots.txt can still appear in Google search results if it's linked from another site, referenced in a sitemap, or mentioned in external backlinks.

This distinction matters because it shapes your strategy. If you block /admin in robots.txt, Googlebot won't crawl it—which is good. But if someone links to yoursite.com/admin from a forum, Google can still index that URL without ever visiting it. The title and description will be missing, but the URL shows up.

If you truly need to hide something from search results, you need multiple layers: robots.txt to prevent crawling, HTTP authentication or password protection to prevent access, and ideally a noindex meta tag as a belt-and-suspenders approach. For sensitive areas like admin panels or user accounts, robots.txt is just the first line of defense.

I learned this the hard way on a CRM platform we built. We blocked /dashboard in robots.txt, assuming it was safe. Months later, a customer's internal link sharing exposed the URL in Google's index. A missing robots.txt is safer than a false sense of security.

The safe default approach—allow, then restrict

Your robots.txt should follow a permissive default: allow everything, then block only what you're certain should never be crawled.

Here's a production-tested example:

html
User-agent: *
Disallow: /api/
Disallow: /admin/
Disallow: /cart
Disallow: /checkout
Disallow: /user/
Disallow: /account/
Disallow: /?*
Disallow: /*?sort=
Disallow: /*?filter=
Disallow: /*?utm_

Sitemap: https://yoursite.com/sitemap.xml

Let me break down why each of these blocks matters:

  • /api/ – API endpoints serve no purpose in search results and waste crawl budget.
  • /admin/, /user/, /account/ – These should never be public.
  • /cart, /checkout – Dynamic state that changes per user. Crawling wastes resources.
  • /*?sort=, /*?filter=, /*?utm_ – Query parameters that create duplicate content or session-specific pages.

The pattern /?* (any root URL with query parameters) blocks most session tracking. But be precise: if your site uses query parameters for legitimate pagination or filtering that should be indexed, don't block them globally. Instead, use a robots meta tag on the page itself or handle it through your crawl settings in Google Search Console.

On an e-commerce platform we run, we blocked filter combinations that created thousands of duplicate category pages. A single Disallow: /*?filter= line reduced our crawl by 40% while preserving all indexable content. Google redirected that crawl budget to discovering new products.

Never block CSS, JavaScript, or images

This is where robots.txt mistakes become expensive. Google needs to render your pages to understand them. If CSS or JavaScript is blocked in robots.txt, Google's rendering engine can't execute it, and the page appears broken to the crawler.

A common mistake I see in legacy systems:

html
User-agent: *
Disallow: /static/
Disallow: /public/
Disallow: /assets/

If your CSS, JavaScript, or fonts live in these directories, you've just told Google it can't render your site properly. Your Core Web Vitals scores drop. Your layouts appear unstyled. Content hidden behind JavaScript never gets extracted. Rankings suffer.

To verify: open Google Search Console, go to URL Inspection, paste your homepage, and click "Test live URL." Then view the Screenshot tab. If your site looks broken or unstyled, robots.txt is probably blocking assets. Fix it immediately.

The safe approach is to allow /static/, /assets/, and /_next/ (or whatever your framework calls it). If you're worried about exposing source maps or debugging information, exclude those files explicitly—don't block entire directories.

Testing before deployment—a single typo costs visibility

I've seen a single misplaced line bring a production site to zero visibility in Google. A developer accidentally deployed Disallow: / instead of Disallow: /admin/. It took three days to notice because nobody was monitoring robots.txt changes.

Here's how to test safely:

  1. Use Google Search Console's robots.txt tester. Go to Settings → Crawl → robots.txt tester. Paste your file and test specific URLs against it. It's not perfect, but it catches syntax errors and obvious mistakes.
  2. Test in staging before production. Deploy your robots.txt to a staging environment, then request the file from outside and verify the behavior.
  3. Monitor robots.txt in your CI/CD pipeline. Add a validation step that checks for Disallow: / (which usually indicates a mistake) or blocks on common asset directories.
  4. Version control your robots.txt. Keep it in Git so you can roll back instantly if something goes wrong.
  5. Set up alerts for robots.txt changes. If someone modifies it in production, you should know within minutes.

On a trading platform, we added a pre-deployment check that failed if robots.txt contained Disallow: / without explicit approval. It's saved us multiple times when someone committed a test file by mistake.

Crawl traps and session parameters

A crawl trap is a pattern that generates infinite URLs. The classic examples:

  • Session IDs in URLs: /page?sid=xyz123 – Each session creates a new URL, and crawlers can keep generating them forever.
  • Calendar navigation: /events?date=2024-01-01 – You could link to every date in history.
  • Sorting and filtering: /products?sort=price&filter=color – Combinations explode combinatorially.
  • Pagination without limits: /page?p=1&p=2&p=3... – A crawler can keep incrementing indefinitely.

Use robots.txt to block these patterns:

html
Disallow: /*?sid=
Disallow: /*?JSESSIONID=
Disallow: /*?utm_source=
Disallow: /*?fbclid=

Query parameters used for tracking (utm, fbclid, gclid) don't add SEO value and create duplicate content. Block them. For legitimate parameters like pagination, use either the rel="next" and rel="prev" link tags or let Google's crawler understand your pagination structure through testing.

Sitemap declaration

robots.txt is a good place to declare your sitemap, but it's optional. You can also submit it directly in Google Search Console. But including it in robots.txt is a courtesy—some crawlers and tools check it first:

html
Sitemap: https://yoursite.com/sitemap.xml
Sitemap: https://yoursite.com/sitemap-news.xml
Sitemap: https://yoursite.com/sitemap-images.xml

You can declare multiple sitemaps if you segment content by type (news, images, video). Google will check them all.

Common mistakes

  • Blocking / by accident. Always test before deploying. A single Disallow: / hides your entire site.
  • Blocking CSS, JavaScript, or fonts. Google can't render your site without them. This kills rankings faster than anything else.
  • Assuming robots.txt prevents indexing. It doesn't. Use noindex meta tags, HTTP authentication, or robots meta tags if you need true blocking.
  • Over-blocking due to outdated concerns. Many developers block /search or /tag pages unnecessarily. If they're part of your site's value, let them be indexed.
  • Ignoring crawl traps. Infinite session IDs or calendar links will waste your crawl budget. Block them.
  • Never updating robots.txt. As your site structure changes, so should your robots.txt. Review it quarterly.

Key takeaways

  • robots.txt controls crawling, not indexing. Blocked URLs can still appear in search results if linked externally.
  • Use a permissive default: allow everything, then restrict only crawl traps, API endpoints, and private areas.
  • Never block CSS, JavaScript, or images. Google needs them to render and understand your pages.
  • Test robots.txt changes in staging and use Google Search Console's tester before deploying to production.
  • Block session parameters and query strings that create duplicate content or infinite crawl paths.
  • Combine robots.txt with other signals (noindex meta tags, authentication, Search Console settings) for sensitive content.
  • Version control your robots.txt and set up alerts for changes.
ShareXLinkedInReddit

Found this useful? Support the writing.

Buy me a coffee
Written by
Expona Admin
Site administrator

Comments

Loading comments…

Leave a comment

Comments are reviewed before they appear. Be kind and stay on topic.

Related articles