← Back to Blog robots.txt Guide: How to Write Rules Without Blocking Your Site

robots.txt Guide: How to Write Rules Without Blocking Your Site

Share:

Here is a mistake that has happened to many websites. A team builds a new site on a test server and adds a robots.txt file that says User-agent: * and Disallow: /, so search engines stay away from the unfinished site. The site goes live, but the file is copied along with it. A few days later, traffic from search drops sharply, because the live site is now telling crawlers to stay out.

A robots.txt file is small, but a single line can change how search engines treat your whole site. This guide explains what it does, what it does not do, and how to write it carefully. You can build the file with our free Robots.txt Generator.

What robots.txt is

robots.txt is a plain text file placed in the root of your domain, so that it opens at an address like https://yourdomain.com/robots.txt. Before crawling a site, well-behaved crawlers such as Googlebot and Bingbot look for this file and read its rules. Some bots ignore it. A file inside a folder is not read, and each subdomain needs its own file.

The main lines are:

  • User-agent: which crawler the rules are for. * means all crawlers.
  • Disallow: a path the crawler is asked not to visit, such as /admin/.
  • Allow: an exception inside a blocked folder.
  • Sitemap: the full address of your XML sitemap.
  • Crawl-delay: a pause between requests. Bing and some others honor it, but Google ignores it.

Disallow is not the same as noindex

This is the most common misunderstanding. Disallow asks crawlers not to crawl a page. It does not promise that the page will stay out of search results. If other websites link to a blocked page, Google may still list the address, often with no description.

If you want a page kept out of Google, allow crawling and add a noindex tag in the page itself. If the page is blocked in robots.txt, Google cannot see that tag. And if a page is truly private, use a password or server login. Our Meta Tags Generator can create the robots meta tag.

Why crawling matters

Search engines do not crawl every page of every site all the time. For a small site, this is rarely a problem. For a large site, with thousands of filter pages, internal search results or session links, it can make sense to keep crawlers away from low-value areas so they spend their time on pages that matter. If your site is small, you probably need only a few rules.

Using the generator

  1. Enter your sitemap address, if you have one.
  2. Choose the default access. "Allow all" is the normal choice. "Block everything" is for a site that must not be crawled yet, so remember to switch it off when you go live.
  3. Add rules. For each rule, pick a bot (all robots, Googlebot, Googlebot-Image, Bingbot, Yahoo, an archive crawler or the AdSense bot), choose Allow or Disallow, and type a path.
  4. Use a preset if it fits. There are presets for WordPress admin, for blocking the AdSense bot and for blocking Google Images.
  5. Copy the text, save it as robots.txt, and upload it to the root of your site.

The preview updates as you type, and the tool runs in your browser. It does not check that your paths exist, so after uploading, open the file in your browser and check it in the robots.txt report in Google Search Console.

One important warning: do not block the AdSense bot (Mediapartners-Google) if you want AdSense to review your pages or show ads on them.

Mistakes to avoid

  • Leaving "Disallow: /" on a live site. Check the file every time you launch or move a site.
  • Blocking CSS or JavaScript files that your pages need. Google uses them to render the page, so blocking them can hurt how it understands the page.
  • Using robots.txt to hide private folders. The file is public. Anyone can open it, and listing a private folder tells them it exists. Use a login instead.
  • Wrong letter case. Paths are case-sensitive on most servers. /admin/ and /Admin/ are different.
  • Wildcards that catch too much. A pattern like /page* can match many more addresses than you expect. Test it first.
  • Related tools

    Our XML Sitemap Generator builds a sitemap that you can reference from your robots.txt file.

    In short

    Keep the file short, write only rules you understand, and test it after every upload. For a small site, an almost empty robots.txt with a sitemap line is often all you need.

M
Written by Muhammad Faraz

Co-founder and developer of AioGalaxy. Builds and maintains the Eaglefly, AIVoice and free tools platforms, and writes the blog.

Enjoyed this? Explore the AioGalaxy toolset

Everything mentioned here — and a lot more — is free to try right now, no sign-up walls.

Explore AioGalaxy →

Comments

No comments yet — be the first to share your thoughts.