Home › Guides › How to Create a robots.txt File

How to Create a robots.txt File

Where the file lives, the four lines that cover most sites, how to upload it on WordPress and static hosting, and how to test it before Google reads it.

A robots.txt file is a plain text file with a fixed name in a fixed place. Creating one is five minutes of work; the mistakes come from the steps people skip, and the skipped step is almost always the testing one.

1. Where the file lives

At the root of the domain: https://example.com/robots.txt. One file per host — www and non-www are separate hosts, as is every subdomain. A file at example.com/blog/robots.txt does nothing, because crawlers only look at the root.

2. The syntax, in four lines

User-agent says which crawler the rules apply to; * means all of them. Disallow lists paths the crawler should not fetch. Allow carves exceptions out of a disallow. Sitemap says where the sitemap lives. A group is one User-agent line followed by its rules, and groups are separated by blank lines. Lines starting with # are comments.

A minimal file that covers most small sites:

User-agent: *
Disallow:
Sitemap: https://example.com/sitemap.xml

If you need examples for specific setups — a blog, WordPress, a shop, a staging site — the examples guide has copy-ready files for each.

3. Write the file

Use the generator on this site: pick the crawlers, list the paths, add the sitemap, copy the result. Or write it by hand in any plain text editor — Notepad, TextEdit in plain-text mode, VS Code. Never use a word processor: it inserts smart quotes and formatting that break the file. Save it as robots.txt, plain text, UTF-8.

4. Upload it

On WordPress, upload through your hosting file manager or FTP to the site root — the folder containing wp-config.php — or use a plugin that writes the file. Check first whether your host serves a virtual robots.txt: if it does, the virtual file is the one crawlers read, and an uploaded file sits unused beside it.

On static hosting — Netlify, Vercel, Cloudflare Pages, GitHub Pages — put robots.txt in the publish directory so it deploys to the root. Then open https://yourdomain.com/robots.txt in a browser and confirm you see your file, not a 404 page or a hosting default.

5. Test it before Google reads it

Paste the file into the tester with five URLs: your homepage, a category page, a deep article, one asset such as a stylesheet or image, and one URL you believe is blocked. If any verdict surprises you, the rule is wrong — fix it now, when the cost is zero. Then check the robots.txt report in Search Console after a day to confirm Google fetched the new file.

6. When it does not work

The file is cached. Google caches robots.txt for up to 24 hours, so a fix takes a day to take effect. Do not keep editing the file while waiting; you will not know which version did what.

Wrong host. The file is on www but the site serves non-www, or the reverse. Each host needs its own file.

Soft 404. The server answers 200 with an error page instead of the file. A crawler treats that as an empty robots.txt — everything allowed — which is the opposite of the intended block.

Case sensitivity. /Admin/ and /admin/ are different paths, and rules match exactly. A disallow for one does not cover the other.

Prefix matching. Disallow: /old matches /old-favourites/ as well as /old/, because matching is by prefix, not by folder. The mistakes guide has the full story on this one, including the product section it ate.

About the author

Hongtao Ren (任宏涛) — Developer based in Xi'an, China. Builds browser-based tools and JetBrains IDE plugins. He built and maintains SerpPrism.

Corrections are the most useful thing you can send. If a tool or guide here gives you a wrong answer, that is a bug, not a judgement call — use the contact page.

Questions

Do I need a robots.txt file at all?

No. A missing file means everything is allowed, which is correct for most sites. You need one when there are sections to keep crawlers out of, AI crawlers to exclude, or a sitemap to announce.

Can I edit robots.txt from the WordPress admin?

Only with a plugin, or through your hosting file manager. WordPress core has no editor for it, and some hosts serve a virtual file that overrides an uploaded one — check which file is actually live first.

How long until a change takes effect?

Google usually refetches the file within a day, but recrawling the affected URLs takes longer. Allow a few weeks for the full effect to show in search results.

Related tools