What Is robots.txt? How to Create, Optimize and Test It
Baris Akkol

A robots.txt file is a plain text file at the root of your website (for example, example.com/robots.txt) that tells search engine crawlers which parts of the site they may request. It controls crawling, not indexing, and that difference causes most of the mistakes we see.
What robots.txt does, and what it does not
It does: ask well-behaved crawlers such as Googlebot and Bingbot not to fetch certain URLs, and point them to your XML sitemap.
It does not:
Remove a page from Google. A blocked page can still be indexed if other sites link to it; Google simply shows it without a description. To keep a page out of search results, allow crawling and use a noindex tag instead.
Protect private content. The file is public, and bad bots ignore it. Use passwords or server rules for anything private.
Fix duplicate content. Use canonical tags or redirects for that.
How the file is structured
A robots.txt file is made of groups. Each group names a crawler and lists rules for it.
User-agent: *
Disallow: /cart/
Disallow: /search?
Allow: /search/help
Sitemap: https://www.example.com/sitemap.xml
User-agent names the crawler. * means all crawlers.
Disallow blocks paths that start with the given value.
Allow makes an exception inside a blocked path.
Sitemap gives the full URL of your sitemap.
Rules are case sensitive, and Google follows the most specific matching rule. * matches any characters and $ marks the end of a URL, so Disallow: /*.pdf$ blocks all PDF files.
What to block, and what not to
Good candidates to block:
Internal search result pages
Cart, checkout and account pages
Filter and sort URLs that create endless combinations
Staging folders or test areas (with password protection as well)
Never block:
CSS and JavaScript files your pages need. Google renders pages like a browser, and blocked resources can make pages look broken to it.
Pages you want to rank.
Pages you want removed from the index (Google must crawl them to see the noindex).
How to create and update the file
Write the rules in a plain text editor and save the file as robots.txt.
Upload it to the root of the domain. Each subdomain needs its own file.
Many platforms, including Wix and Shopify, generate the file for you and offer an editor in the SEO settings. Use that editor instead of uploading a file.
Add your sitemap URL at the end.
How to test robots.txt
Open yourdomain.com/robots.txt in a browser and check that it loads with a 200 status.
In Google Search Console, the robots.txt report (under Settings) shows the version Google fetched and any errors.
Use the URL Inspection tool on an important page. It tells you whether the page is blocked by robots.txt.
After a site launch or migration, check the file again. A leftover Disallow: / from a staging site is one of the most common causes of a sudden traffic drop.
Common mistakes
Disallow: / copied from a development site, blocking everything.
Blocking a page and adding noindex to it. Google cannot see the noindex, so the page may stay indexed.
Blocking CSS or JavaScript folders.
Forgetting that rules are case sensitive (/Blog/ is not /blog/).
Relying on robots.txt to hide sensitive files.
Frequently asked questions
Do I need a robots.txt file? No, but it is good practice. Without one, crawlers assume everything is allowed. A simple file with your sitemap URL is enough for most small sites.
How quickly does Google notice changes? Google usually refreshes its copy within a day. You can request a recrawl in Search Console's robots.txt report.
Can robots.txt block AI crawlers? You can add rules for specific crawlers, such as GPTBot or Google-Extended, that respect robots.txt. Whether to block them is a business decision: blocking can also reduce how often AI assistants cite your content.
Need a technical check?
Request a free website analysis and we will check your robots.txt, sitemap and indexing as part of it.





