How to Optimize Robots.Txt for SEO

Updated:

A copied robots.txt rule can block your best guide just as easily as an unwanted search page. The file may contain only a few lines, but those lines deserve more care than a quick paste from another website.

The difficult part is deciding what each rule should affect and checking that it stops there. A file that looks tidy can still block the images or scripts your pages need. The guide below shows how to restrict unwanted crawling while keeping those pages and files accessible, with checks to catch mistakes and a way to undo a bad change.

What Should Robots.Txt Do for SEO?

To optimize robots.txt for SEO, keep important pages and their supporting files crawlable, restrict selected unwanted URL patterns, include your sitemap address, and test the result.

Start by separating three jobs:

  • Crawling means a search engine can request a URL and read its contents.
  • Indexing means a search engine includes a page in its search index.
  • Security means unauthorized visitors cannot access private content.

Robots.txt controls crawl access for crawlers that follow its instructions. It does not handle all three jobs.

What Should Robots.txt Do For Seo?: Robots.txt: Crawling, Indexing &Amp; Security; Crawl Access; Robots.txt; Search Exclusion; Noindex + Crawl Access; Private Content; Authentication; A Blocked Url Can Still Appear In Search

A blocked page URL can still appear in Google. To exclude a public page from search, use a robots meta tag or an X-Robots-Tag response header containing noindex, and keep that page accessible to Google. Google does not support noindex inside robots.txt. Google’s indexing guidance explains this distinction.

Private customer records and paid downloads need authentication or another access control. Robots.txt is public, so listing a private folder there does not protect it.

For a smaller blog, I would fix access rules before trying to control how much Google crawls. A longer block list is not an achievement, and robots.txt changes do not guarantee indexing or better rankings.

1. Find and Back up Your Live Robots.Txt

Open your website’s root address followed by /robots.txt:

https://example.com/robots.txt

Save the current contents as a plain-text backup. Also record the address and response status. You can find the status in your browser’s developer tools under Network by reloading the file and selecting its request.

A successful response will normally show 200. A 404 means the file was not found, which ordinarily leaves Google with no robots.txt restrictions to apply. A timeout or server failure needs separate investigation.

1. Find And Back Up Your Live Robots.txt: Find The Right Robots.txt Before Editing; Https://Example.com/Robots.txt; Status: 200; Http://Example.com; Https://Shop.example.com; Https://Example.com:8443; Different Protocol, Host Or Port: Check

Check the address carefully. Rules apply to the protocol, hostname, and port where the file is served. Your HTTPS file does not automatically govern HTTP, a separate shop subdomain, or another nonstandard port. These boundaries follow Google’s file-location requirements.

Next, find what controls the public response. It might be:

  • A physical file in your website’s root folder.
  • The content management system (CMS) you publish with, such as WordPress, or an SEO plugin.
  • A hosting setting.
  • A server setting or a content delivery network (CDN), such as Cloudflare, that serves files for your site.

On WordPress, I would check the existing SEO setup before installing anything else. If Rank Math already manages the file, work through that setup and verify the public result.

Know how to restore the saved version before editing. The backup needs to match the source that actually serves the file.

2. Decide Which URLs to Allow or Block

Add a restriction when you can name the problem it solves. Use URLs your site actually produces, and check crawl reports or server logs if they are available. Server logs record requests made to your website, including crawler visits.

For the running example, imagine your site publishes indoor-rabbit care guides and sells a printable care planner. The guides live under /guides/, the sales page is /care-planner/, and internal search results use /search/.

2. Decide Which Urls To Allow Or Block: Robots.txt Must Allow Pages And Their Assets; /Care-Planner/; Styles; Scripts; Images; /Assets/ Must Remain Crawlable; Page Allowed ≠ Rendering Verified; Test Actual Asset Urls Too

Write down the intended behavior before writing rules:

URL or PatternPurposeIntended Search VisibilityCrawl DecisionReason
/Introduces the site and links to key contentEligible for searchAllowMain entry point
/guides/Contains useful care articlesEligible for searchAllowReaders discover the guides through search
/care-planner/Sells the printable plannerEligible for searchAllowImportant product page
/category/housing/Groups useful housing guidesEligible if the archive helps readersAllowProvides a useful browsing page
/guides/page/2/Links to older guidesNo separate indexing target hereAllowKeeps older articles reachable
/assets/Holds styles, scripts, and imagesSupports page renderingAllowGoogle needs these files to understand pages
/search/Generates internal search resultsNo search listing wantedBlock only if crawl restriction is the goalKeep accessible if relying on noindex

The last row requires a decision. If those search pages must stay out of Google, leave them crawlable and use noindex. The blocked-search example below assumes you have chosen to restrict crawling and understand that this alone does not guarantee removal from search.

2. Decide Which Urls To Allow Or Block: Choose The Right Seo Control For Each Url; Restrict Crawling; Robots.txt Disallow; Does Not Guarantee Search Removal; Exclude A Public Page From Search; Noindex + Crawl Access; Identify The Preferred

Judge category, tag, and author archives by their usefulness. I would keep a well-organized archive that helps readers find related guides. I would skip automatic rules that block every archive simply because it is an archive.

Also check the files your pages load. I once copied a robots.txt template into a draft for a digital-product site and found that it blocked a stylesheet used by the sales page. The page URL passed my first check, but its supporting file failed. That is why I test assets alongside pages. Google specifically warns against blocking resources needed to understand a page in its robots.txt guidance.

Duplicate URLs need a different decision. Use a canonical tag to identify the preferred version, or redirect a retired duplicate to that version. Leave the relevant URLs crawlable so Google can read those signals. Google advises against using robots.txt for canonicalization.

3. Write Precise Robots.Txt Rules

Choose the Crawler Group

The basic fields have simple jobs:

  • User-agent: selects the crawler that should follow the group.
  • Disallow: restricts matching URL paths.
  • Allow: permits a matching path, usually as an exception to a broader restriction.

URLs remain crawlable unless an applicable rule blocks them. You do not need a separate Allow line for every guide.

Choose The Crawler Group: Googlebot Does Not Inherit Wildcard Rules; User-Agent: * Disallow: /Search/ User-Agent: Googlebot Disallow: /Preview/; Most Specific Matching Group Applies; /Search/ — Allowed; /Preview/ — Blocked; Repeat Shared

Start with User-agent: * for shared rules. The asterisk here means the group applies when no more specific crawler group matches.

Add a crawler-specific group only when that crawler needs different access. Google chooses its most specific matching group and does not inherit the wildcard group’s restrictions. Repeated groups matching that specific crawler are combined. Google’s group-selection rules explain this behavior.

Choose The Crawler Group: Googlebot Combines Repeated Matching Groups; User-Agent: Googlebot Disallow: /Search/; User-Agent: Googlebot Disallow: /Drafts/; Both Matching Groups Contribute Rules; /Search/; /Drafts/; Review The Complete File, Not One

For example, if you add a separate Googlebot group, repeat any shared restrictions Googlebot still needs. Otherwise, a block that works for other crawlers may stop applying to Googlebot.

I would keep one shared group unless there is a clear reason to maintain more.

Match Unwanted Paths Narrowly

Write one directive per line. Start path values with /, and use # for comments explaining decisions that may be unclear later.

Field names are case-insensitive, but paths are case-sensitive. /Search/ and /search/ are different matches.

Pay particular attention to these two lines:

DirectiveEffect Within Its Crawler Group
Disallow:Adds no restriction
Disallow: /Blocks every path

That single slash can change the whole file’s effect.

Match Unwanted Paths Narrowly: Robots.txt: One Slash Changes The Match; Disallow:; No Restriction Added; Disallow: /; Every Path Blocked In This Group; Disallow: /Search/; /Search/?Q=Hay — Blocked; /Search-Tips/ — Allowed; Disallow: /Search

For the rabbit-care example, the narrow directory restriction is:

Disallow: /search/

It blocks /search/?q=hay and leaves /search-tips/ accessible. Using /search without the trailing slash would match both because both start with that text.

Two pattern characters help when a plain prefix is insufficient:

  • * matches zero or more characters.
  • $ marks the end of the match.

For example, /search$ matches /search, but not /search?q=hay. The query string matters when testing an end marker. These matching rules are defined in the Robots Exclusion Protocol.

Match Unwanted Paths Narrowly: Robots.txt Allow Exceptions: The Query String Matters; Disallow: /Search/ Allow: /Search/Help.html$; $ Requires The Match To End Here; /Search/Help.html; Allowed: Specific Exception Matches

If the search directory contains a help page that should remain crawlable, add an exception:

Disallow: /search/
Allow: /search/help.html$

Google uses the most specific matching path rule. Allow wins when conflicting rules are equally specific, and moving a line to the bottom does not make it override everything above it.

Avoid blanket query-string blocks such as Disallow: /*?. A question mark does not tell you whether a URL is useful. Review the actual parameter, its purpose, and the combinations your site generates.

For Google crawling, leave out unsupported fields such as Crawl-delay and Host. Extra lines do not make the file more effective.

Add the Sitemap Location

A sitemap lists pages for search engines, while a sitemap index links to several sitemap files. Find the file your site uses and open it to check that it lists the expected page URLs or sitemap links. Your CMS or SEO plugin may already generate one.

Add Sitemap: followed by its full address, including https:// and the hostname. This declaration is independent of crawler groups.

Add The Sitemap Location: Add A Verified Sitemap To Robots.txt; User-Agent: * Disallow: /Search/ Sitemap: Https://Example.com/Sitemap.xml; Example Address: Replace With Yours; Crawl Restriction; Sitemap Discovery; Sitemap Declaration Is Independent

Here is the complete illustrative file for the rabbit-care site:

User-agent: *
Disallow: /search/

Sitemap: https://example.com/sitemap.xml

Replace the sitemap placeholder with your verified address. Remove the search restriction if your site does not use that path or you have chosen the crawlable noindex approach.

Add The Sitemap Location: Xml Sitemap Or Sitemap Index?; A Sitemap Lists Page Urls; Guide; Product Page; A Sitemap Index Lists Sitemap Files; Guide Sitemap; Page Sitemap; Verify The File Your Site Actually Uses; List Preferred Urls Intended For

There are no explicit allowances for /guides/, /care-planner/, or /assets/ because this file does not block them.

Your existing rules may need more care than this short example. The AI Crawl Directive Assistant can prepare a site-specific draft and matching test URLs so you have something concrete to review before publishing.

Lead Magnet Cover
FREE AI SKILL

Free AI Crawl Directive Assistant

Use AI to plan what search engines should crawl or leave out of results while keeping the settings you still need.
Send My AI Crawl Directive Assistant ❯
Instantly delivered to your inbox
Customer Avatar 1
Customer Avatar 2
Customer Avatar 3
Customer Avatar 4
Rated highly by 2,500+ users

Keep the sitemap focused on preferred URLs intended for indexing, and make sure those pages remain crawlable. Google’s sitemap guidance recommends listing the versions you want shown in search.

4. Test the Draft Before Publishing

Test the complete proposed file, including existing rules you plan to retain. Checking one new line in isolation can miss a conflicting group or exception.

Screpy’s robots.txt tester checks pasted drafts or the live file. To test unpublished rules, choose Paste robots.txt and paste the complete draft. Enter your site’s origin: the protocol and hostname, plus a port if your site uses a nonstandard one. Add the URL or path to check, select Googlebot, and run the test.

Read the matching group and deciding rule alongside the allowed or blocked result.

Use a small test sheet like this. The expected results below apply to the sample file; no tests have been run against your website.

URLCrawlerExpected AccessActual Result: Current → DraftExpected Deciding Rule
/GooglebotAllowedNot testedNo matching restriction
/guides/indoor-rabbit-enrichment/GooglebotAllowedNot testedNo matching restriction
/care-planner/GooglebotAllowedNot testedNo matching restriction
/assets/site.cssGooglebotAllowedNot testedNo matching restriction
/assets/planner-preview.jpgGooglebotAllowedNot testedNo matching restriction
/sitemap.xmlGooglebotAllowedNot testedNo matching restriction
/search/?q=hayGooglebotBlockedNot testedDisallow: /search/
/search-tips/GooglebotAllowedNot tested/search/ does not match
4. Test The Draft Before Publishing: Robots.txt Draft Tests: Cover Pages And Edge Cases; Expected Examples Only — Not Tested; Important Content + Assets; /Care-Planner/ — Expect Allowed; /Assets/Site.css — Expect Allowed; Block Target + Near Match

Run these checks against both the current file and the draft, then replace “Not tested” with the results. Investigate any changed access you did not intend.

Add tests for:

  • Important JavaScript files and actual image URLs.
  • Capitalization and trailing-slash variations your site generates.
  • Query strings in their real positions and combinations.
  • Every Allow exception.
  • Existing crawler-specific groups and other relevant crawlers.

If you added the help-page exception, /search/help.html should be allowed, but /search/help.html?topic=hay should be blocked. The $ limits the exception to the URL without a query string. Test both to confirm that this is the behavior you want.

Resolve parsing warnings and unexpected results before publishing. A draft tester checks rule behavior; it cannot prove that Google can fetch your live website.

5. Publish and Check the Live File

Publish through the CMS, hosting control, or other source you identified earlier. If uploading a physical file, use UTF-8 plain text named exactly robots.txt at the relevant site root.

Then open its public address while logged out. Confirm that it returns the intended text and a successful response. A login screen, HTML error page, or security challenge is not the result you want, even if something appears in the browser.

If an older version appears, clear the relevant site or CDN cache and check again. For a site using Cloudflare, include its cache in that investigation.

5. Publish And Check The Live File: Publish Robots.txt, Verify It, Restore If Needed; Publish Through The Serving Source; Robots.txt · Utf-8 Plain Text; Open The Public File While Logged Out; Intended Text + Successful Response; Repeat Url Tests On

Repeat your representative URL tests using the live file. The draft passing does not prove that the correct version was published.

Treat retrieval problems promptly. Google generally interprets 4xx responses other than 429 as having no robots.txt restrictions. Server failures and rate-limit responses have different handling and can interrupt crawling. Google documents those response rules here.

If an important page or asset becomes unintentionally blocked, restore the saved version immediately. Check the public response, correct the responsible rule in your draft, and repeat the tests before republishing.

6. Verify Access in Search Console

Open Search Console’s robots.txt report and check whether Google successfully fetched the file. Review parsing issues, the fetched contents, and the last fetch time.

The site you select in Search Console is called a property. This report works with a Domain property, covering a domain and its subdomains, or a URL-prefix property set to a site root, such as https://example.com/. If yours covers only a folder, such as https://example.com/guides/, switch to a site-level property.

After fixing a critical error or unblocking important URLs, request a robots.txt recrawl. Compare Google’s fetched contents with your deployment once the report updates. Your browser seeing the new file does not mean Google has refreshed its cached copy.

6. Verify Access In Search Console: Search Console: Verify Robots.txt And Page Access; 1. Google'S Robots.txt Copy; Fetch Succeeded?; Contents Match Deployment?; Browser Updates Do Not Prove Google Refreshed; 2. Live Page Access; Crawl Allowed?

Next, inspect a representative guide and the planner sales page. Run Test live URL and review:

  • Crawl allowed? should show permission for pages you want crawled.
  • Page fetch should succeed.
  • Indexing allowed? should permit indexing for pages intended for search.
  • The tested page’s screenshot and resource details should show that essential content and supporting files load.

Read those results together. An indexing-permission result alone cannot prove that Google fetched the page successfully. Also distinguish the live test from the previously indexed version. A successful live check establishes access at test time and does not guarantee inclusion in search, as Google explains in its URL Inspection documentation.

Finally, review robots.txt exclusions in the Page indexing report. A newly blocked care guide needs attention. An intentionally restricted internal-search URL may be behaving exactly as planned.

Success means your intended access rules work, important pages and assets remain crawlable, the sitemap is discoverable, and robots.txt has no unresolved retrieval or parsing problems. Unrelated indexing issues need their own investigation.

Keep the backup, test sheet, and a short change log together. Record what changed and why. Recheck after changes to URL structures, themes, plugins, hosting, or the publishing system, and remove obsolete rules once you understand their original purpose.

What Next?

Save your live robots.txt and make a test list containing your homepage, one useful guide, one sales page, and their essential assets. Establish how those URLs behave before adding a restriction.

Use the social buttons to share this guide when a robots.txt edit is on the task list; the before-and-after checks can make that edit easier to review.

Which URL pattern on your site are you least sure about allowing or blocking? Leave it in the comments, along with any other questions.

Share this post with your friends & followers:
Abhishek is a data scientist by day & an online entrepreneur by night. He is known for his ability to simplify complex concepts and make them accessible to a wider audience. He started Passive Book to share his insights and experiences on how to effectively build an online business, which has quickly become a go-to resource for anyone looking to bootstrap an online business from scratch.

Leave a Comment

Build an Online Business 
Without Quitting Your Job

Join 10,000+ solopreneurs building six-figure online businesses from scratch with limited time & tight budgets using smart systems & AI automations.
Optin Form - Main

Free Bonus: Get access to our AI workflows & cheat sheets
Person sitting with laptop in home office environment with launching rocket, coffee mug, sleeping dog, bookshelf, and house plant illustrating work-from-home online business lifestyle. Decorative image.
Thank you for sharing

Follow Us On: