
In this article
A robots.txt file is a small text file that tells search engines which parts of your website they may crawl. Written well, it keeps crawlers away from pages you do not want visited. Written badly, one stray line can hide your entire site from Google.
This guide applies to every website, whether it runs on WordPress, Shopify, Wix, Joomla, Magento or custom code.
What robots.txt does, and what it does not
- It does: ask well-behaved crawlers not to fetch certain paths, and point them to your XML sitemap.
- It does not hide pages. A blocked address can still appear in search results if other sites link to it. To keep a page out of search, use a
noindextag and leave the page crawlable so the tag can be read. - It is not security. The file is public, so anyone can read it. Never list secret folders there, and protect private areas with a login.
- Bad bots ignore it. Only crawlers that choose to follow the rules obey them.
Where it lives
The file must sit at the root of the domain: https://yourdomain.com/robots.txt. Every subdomain needs its own file. If the file returns a 404, crawlers assume everything may be crawled.
The basic syntax
User-agent: *
Disallow: /cart/
Disallow: /search
Allow: /search/help
Sitemap: https://yourdomain.com/sitemap.xml
User-agentnames the crawler the rules apply to.*means all of them.Disallowblocks a path.Allowmakes an exception inside a blocked path.Sitemapgives the full address of your sitemap.*matches any characters and$marks the end of an address, for exampleDisallow: /*.pdf$.
What to block, and what to leave alone
Reasonable to block:
- Cart, checkout and account pages.
- Internal search result pages and endless filter combinations.
- Staging or test areas that are not behind a login. Better still, put those behind a password.
Do not block:
- CSS and JavaScript files. Google needs them to see your pages as visitors do.
- Pages you want to rank.
- Pages you want removed from search. Blocking stops Google from seeing the
noindextag.
The mistakes that cause real damage
Disallow: /for all crawlers. This blocks the whole site. It often arrives when a staging site's file is copied to the live site.- Blocking CSS, JavaScript or images, which stops Google rendering the page properly.
- Using it to hide sensitive pages, which advertises their location to everyone.
- Typos and wrong case. Paths are case-sensitive, and a misspelt directive is ignored.
- A missing or unreachable file. A server error on
/robots.txtcan make crawlers hold back from the whole site. - A file added or changed by a hacker. If your rules change and you did not change them, run a malware check.
Step 1: create the file
Use the free robots.txt generator to build a file from simple choices, then upload it to the root of your site. Most platforms also have a built-in setting or editor for it.
Step 2: test it
Run your domain through the robots.txt and sitemap tester. It shows whether the file loads, how it reads your rules and whether a given page is blocked. Test your most important pages, such as the home page, product pages and blog posts.
Step 3: link your sitemap
Add a Sitemap: line, and keep the sitemap itself clean. Our guide on creating and submitting an XML sitemap shows how.
Step 4: watch Search Console
In Google Search Console, the Pages report lists addresses "Blocked by robots.txt". Review it after every change to make sure only the pages you meant to block are there.
Common questions
Do I need a robots.txt file?
Not strictly. Without one, crawlers read everything. But a short file with a sitemap line is good practice, and it stops crawlers wasting time on pages with no search value.
Will robots.txt stop my pages appearing in Google?
Not reliably. Use noindex for that, or put the page behind a login.
How long do changes take to apply?
Google usually re-reads the file within a day, but it can take longer for large sites.
Should I block AI crawlers?
That is your choice. Many AI crawlers publish a name you can add under User-agent, and well-behaved ones respect it.
Free tools for this problem
- Robots.txt & sitemap tester: Test crawl rules for Google, Bing and AI bots.
- Robots.txt generator: Block folders, add your sitemap and opt out of AI crawlers.
- XML sitemap generator: Crawl up to 100 pages and download a ready-to-upload sitemap.xml.
