A robots.txt file is a plain text file at the root of your website that tells crawlers which parts of the site they may and may not request. To create one, write a few rules using User-agent, Disallow, Allow, and Sitemap, save the file as robots.txt, upload it to your site’s root so it loads at yourdomain.com/robots.txt, and test that it behaves as intended.
This guide walks through each step, explains the syntax, shows a safe starting file, and points out the mistakes that cause the most damage. One point matters before anything else: robots.txt controls crawling, not whether a page appears in search results. For the difference, see robots.txt vs. noindex.
What Does a robots.txt File Do?
Before a well-behaved crawler fetches pages from your site, it checks your robots.txt file for rules about where it may go. You can use it to keep crawlers out of sections such as admin areas, internal search results, or cart pages, and to point them to your sitemap.
It is guidance, not security. Reputable crawlers follow it, but bad bots can ignore it, and the file itself is public, so anyone can read which paths you listed. Do not use robots.txt to hide confidential content; protect that with a login instead.
Where Does robots.txt Go?
The file must sit at the root of the host it applies to, for example https://ngepush.com/robots.txt. A file in a subfolder is not valid. Each subdomain, such as blog.example.com, needs its own file, and the rules apply only to the protocol, host, and port that serve the file.
The Four Rules Google Supports
Google’s interpretation of the robots.txt standard supports four fields:
| Field | What it does |
|---|---|
User-agent | Names the crawler the following rules apply to; * means all crawlers |
Disallow | A URL path the crawler must not fetch |
Allow | A URL path the crawler may fetch, often used as an exception to a broader Disallow |
Sitemap | The full URL of your sitemap |
Other fields, such as crawl-delay, are not supported by Google. Paths must begin with / and are case sensitive, so /Photos/ and /photos/ are different. The User-agent value is not case sensitive.
How to Create a robots.txt File
Step 1: Decide what you want to block
Start from the opposite question: what must crawlers be able to reach? Most sites want nearly everything crawlable. Common candidates for blocking are admin areas, internal search result pages, and cart or checkout pages. Do not block CSS or JavaScript files that Google needs to render your pages.
Step 2: Write the rules
Each group starts with a User-agent line, followed by its rules. A simple, safe file looks like this:
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Sitemap: https://example.com/sitemap.xml
An empty Disallow: line means nothing is blocked, while Disallow: / blocks the entire site. Be very careful with that second one.
Step 3: Save it as plain text
Save the file as robots.txt, in all lowercase, as plain text with UTF-8 encoding. Do not use a word processor, which can add hidden formatting. If you would rather not write it by hand, use the Robots.txt Generator to build a valid file and download it.
Step 4: Upload it to your site root
Place the file in the top-level folder of your site, alongside your homepage files. In WordPress, that is the same folder that contains wp-admin and wp-content.
Step 5: Test it
Open yourdomain.com/robots.txt in your browser. You should see the text of your file. Then check the pages and folders you care about:
- Confirm important pages are not blocked.
- Confirm blocked paths are really blocked.
- Use the robots.txt report in Google Search Console to see how Google read the file.
Google generally caches robots.txt for up to about a day, so changes may not take effect immediately.
robots.txt in WordPress
If your site does not have a physical robots.txt file, WordPress generates a virtual one on the fly. A default version typically contains:
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Many SEO plugins let you edit this virtual file, and some add a sitemap line. If you upload a physical robots.txt to your site root, it takes precedence over the virtual one, so edits made in a plugin may seem to have no effect. Also note that the “Discourage search engines from indexing this site” setting in WordPress works differently from robots.txt, which is covered in the noindex comparison.
Limits to Know
Google reads at most 500 KiB of a robots.txt file and ignores anything after that. If your file grows large, consolidate rules into broader patterns.
Common Mistakes
- Blocking everything by accident.
Disallow: /underUser-agent: *stops all compliant crawlers. - Treating robots.txt as a way to hide pages. A blocked URL can still appear in search results if other pages link to it.
- Blocking resources needed for rendering, such as CSS and JavaScript.
- Putting the file in the wrong place. It must be at the root.
- Ignoring case. Paths in rules are case sensitive.
- Forgetting to retest after a site change, such as moving to a new CMS or a staging-to-live launch.
For ready-made rules for common situations, see robots.txt examples. Robots.txt is one of several on-page and technical checks to run before you publish; the on-page SEO checklist covers the rest.
Conclusion
A robots.txt file is short, but it has real consequences. Write simple rules, save it as plain text, upload it to your root, and test it. Block only what you must, and remember that it controls crawling, not indexing.
Frequently Asked Questions (FAQ)
What is a robots.txt file used for?
It tells crawlers which paths on your site they may or may not request, and it can point them to your sitemap.
Where should I put the robots.txt file?
At the root of your site, so it loads at yourdomain.com/robots.txt. Each subdomain needs its own file.
Does robots.txt stop a page from appearing in Google?
Not reliably. It stops compliant crawlers from fetching the page, but Google may still show the URL, without a description, if other pages link to it. To keep a page out of results, use noindex.
Is robots.txt secure?
No. It is a public file that well-behaved crawlers follow voluntarily. Do not use it to protect private content.
Do I need a robots.txt file at all?
It is not required. Without one, crawlers assume they may fetch the whole site. Create one when you want to block certain sections or point crawlers to your sitemap.
