How to Create a Robots.txt File
A robots.txt file is a small text file that sits at the root of your website and tells search engines which pages they may crawl and which they should leave alone. It takes two minutes to create, and most websites need only a few lines. This guide shows you how to write one, where to put it, and the mistakes that can accidentally hide your whole site from Google.
What a robots.txt file actually does
Crawlers check it before they start
Search engines send crawlers to visit your pages, and before a crawler starts work it checks for a file called robots.txt at the root of your domain. The file is a set of plain-text instructions: which parts of the site the crawler may visit, which parts it should skip, and where your sitemap lives. It is a polite request, not a lock — well-behaved crawlers like Googlebot follow it, but nothing forces a bad bot to obey.
What it does not do
Two things robots.txt does not do are worth knowing before you write one. First, it does not hide a page from search results: if other pages link to a blocked URL, Google may still list it, usually without a description. To remove a page from results you need a noindex tag, not a robots.txt rule. Second, it does not protect private content — anyone can open your robots.txt file and read it, so never use it to hide sensitive URLs. Passwords protect private pages; robots.txt only manages crawling.
The rules most websites need
Allow all, block a few, point to the sitemap
Most sites need only three things in robots.txt: allow everything by default, block the handful of areas that waste crawl time, and point to the sitemap. A typical file looks like this: User-agent: * on the first line, then Disallow lines for the admin area, the login page, the cart and internal search results, and finally a Sitemap line with the full sitemap URL. That is the whole file for most small sites.
Wildcards work — with two details to get right
Two details are easy to get wrong. Wildcards work in Google's reading of robots.txt — an asterisk matches any sequence of characters, and a dollar sign marks the end of a URL — but not every crawler supports them, so keep your rules simple enough that a basic crawler still reads them correctly. And crawl-delay, a line that asks crawlers to wait between requests, is ignored by Google entirely, so do not rely on it to protect a slow server.
Create your robots.txt file in four steps
- Decide what to block. Admin areas, login and account pages, carts and checkout, internal search result pages, and any staging or test area. Do not block your CSS, JavaScript or image files — Google needs them to render your pages properly, and blocking them can hurt how your pages are understood.
- Write the rules. The quickest way is a browser tool: open the Robots.txt Generator, add your allow and disallow rules, paste your sitemap URL, and copy or download the finished file. A plain text editor works too — one rule per line, no formatting, saved as robots.txt.
- Upload it to your website root. The file must live at https://example.com/robots.txt — a copy in a subfolder is ignored, and each subdomain needs its own file. Upload it with your hosting file manager or FTP. WordPress users can use an SEO plugin with a robots.txt editor, or upload the file manually.
- Test it before you trust it. Open the URL in a browser and confirm the file loads. Then check it in Google Search Console: the robots.txt Tester shows whether a given URL is blocked, and URL Inspection confirms Google can fetch the file. Re-check after every change — a typo here can block the whole site.
Mistakes that hide your site from Google
The classic disaster is a single line: Disallow: / blocks the entire site. It is usually a leftover from a staging site that went live with its test robots.txt still in place. If your pages suddenly drop out of search results, check robots.txt first — it takes ten seconds and it is the most common cause of a sudden disappearance.
The other common mistakes are subtler. Blocking CSS and JavaScript files stops Google rendering pages properly. Using robots.txt to hide private pages gives a false sense of security, since the file itself is public. And assuming every bot obeys the rules is wishful thinking: scrapers and malicious bots ignore robots.txt, so anything genuinely private needs a password, not a Disallow line.
Other ways to create a robots.txt file
If you run WordPress, SEO plugins like Yoast and Rank Math include a robots.txt editor in their settings, which is the easiest route on that platform. Shopify, Wix and Squarespace generate a robots.txt file automatically, with limited options to edit it. And for a static or hand-built site, a text editor plus your hosting file manager is all you need.
Whichever route you take, the file itself is identical: plain text, at the root, with one rule per line. The browser generator is the fastest option when you want a correct file without installing a plugin or learning the syntax.
Related guides
- How to Create an XML Sitemap (Free, in Minutes) — list every page for search engines in an XML sitemap.
- How to Add Schema Markup to a Website (JSON-LD, Free) — add JSON-LD schema so Google understands your pages.
- How to Check a Page for Basic SEO (Free Checklist) — a five-minute checklist before you publish a page.
Questions people ask
Where does the robots.txt file go?
At the root of your domain, so it loads at https://example.com/robots.txt. A copy in a subfolder is ignored by crawlers, and each subdomain needs its own separate file.
Does robots.txt hide a page from Google?
No. It only tells crawlers not to visit the page. If other pages link to it, Google may still list the URL in search results. To remove a page from results, use a noindex tag instead.
What happens if I block my whole site by accident?
Google stops crawling new pages, and over time your pages can drop out of search results. Remove the bad rule, save the file, and ask Google to re-crawl in Search Console. Recovery can take days or weeks, so check the file after every change.
Do I need a robots.txt file at all?
Strictly no, a site works without one. But it is a two-minute job that gives you control over crawl budget and keeps admin and search pages out of the crawl queue, so there is little reason to skip it.