Robots.txt generator

Create a valid robots.txt that tells search engines what to crawl and what to skip — including your sitemap location.

Robots.txt Generator

Create a valid robots.txt that tells search engine crawlers what to index and what to skip — plus your sitemap location.

Generated File

robots.txt — place at your site root

How to use this tool

robots.txt is the first file a well-behaved crawler requests from your domain. It controls crawling: which paths bots may fetch. That protects your crawl budget and stops search engines wasting attention on carts, admin panels and internal search results.

What it does not control is indexing. This distinction causes more SEO damage than any other robots.txt misunderstanding. If another site links to a page you've disallowed, Google can still list that URL in search results — it simply won't have crawled the content, so it shows a bare URL with no description. To keep a page out of the index you must let it be crawled and serve a noindex meta tag. Blocking it in robots.txt actively prevents Google from seeing that tag.

The mistake that deindexes entire sites

A single line — Disallow: / — blocks your whole site. It's the correct setting for a staging environment, and catastrophic on production. The classic disaster is a staging robots.txt being deployed to live, and it happens often enough that checking robots.txt should be a standard post-deploy step.

Two subtler traps: robots.txt must live at the domain root (example.com/robots.txt) — anywhere else and it's ignored entirely. And it doesn't apply across subdomains, so blog.example.com needs its own file.

Never use it to hide sensitive paths

robots.txt is a public file that anyone can read, and listing a path there advertises its existence. Writing Disallow: /admin-panel-v2/ tells every curious visitor exactly where to look. It's an instruction to polite crawlers, not an access control, and malicious bots ignore it completely.

Anything genuinely sensitive needs authentication, not a crawler directive. Our security essentials covers the difference between obscurity and actual protection.

Always declare your sitemap

Adding a Sitemap: line is the cheapest indexing help available. It works for every major search engine, requires no account, and gives crawlers a direct route to every URL you care about. Use the absolute URL, and note that this directive is independent of user-agent groups — it applies globally wherever you place it.

After changing robots.txt, test it. Google Search Console's robots.txt report shows exactly how Googlebot interprets your file, which is far more reliable than reading the rules yourself and hoping.

Developer Implementation Guide: Serving robots.txt Dynamically

While static sites can just drop a robots.txt file in their public folder, dynamic applications often need to change their robots policy based on the environment (e.g., blocking crawlers entirely on staging environments).

Implementation in Node.js / Express

Here is how to serve a dynamic robots.txt file that automatically blocks crawlers unless the application is running in the production environment.


const express = require('express');
const app = express();

app.get('/robots.txt', (req, res) => {
  res.type('text/plain');
  
  if (process.env.NODE_ENV === 'production') {
    // Production: Allow everything, declare sitemap
    res.send(User-agent: *
Allow: /
Sitemap: https://yourdomain.com/sitemap.xml);
  } else {
    // Staging/Dev: Block everything
    res.send(User-agent: *
Disallow: /);
  }
});
        

This simple middleware guarantees that your staging server will never accidentally be indexed by Google, which is a common cause of duplicate content penalties.

Frequently asked questions

Does robots.txt stop a page appearing in Google?

No. It stops crawling, not indexing. A disallowed page can still be listed if other sites link to it — Google just shows the bare URL with no description. To keep a page out of the index, allow crawling and use a noindex meta tag instead.

Where does robots.txt need to be located?

At the root of the domain, for example example.com/robots.txt. Placed anywhere else it is ignored completely. Each subdomain needs its own file — blog.example.com will not use the main domain’s robots.txt.

Can I use robots.txt to hide private pages?

No. It is a public file, so listing a path there advertises its existence to anyone who looks, and malicious bots ignore it entirely. Anything genuinely private needs authentication or server-level access control.

Should I include my sitemap in robots.txt?

Yes. A Sitemap: line with the absolute URL is the cheapest indexing hint available, works across all major search engines, and applies globally regardless of which user-agent group it sits in.