Creating an SEO-Friendly robots.txt File (Step-by-Step)

8 min readSEO Expert Team

Complete step-by-step guide to creating an optimized robots.txt file. Learn proper syntax, user-agent rules, sitemap inclusion, and avoid common mistakes that hurt SEO.

What Makes robots.txt SEO-Friendly

An SEO-friendly robots.txt file does more than just block pages—it helps search engines crawl your site efficiently while protecting your SEO value and improving search rankings.

Allows Important Content

Never blocks pages you want ranked. Only restricts pages that don't need indexing like admin areas, duplicate content, and thank-you pages.

Includes Sitemap Location

Always references your XML sitemap to help search engines discover all your important pages quickly and efficiently.

Doesn't Block CSS/JS

Allows proper page rendering evaluation by not blocking stylesheets and JavaScript files that Google needs to see.

Uses Proper Syntax

Avoids errors that could break functionality with correct capitalization, formatting, and URL structures.

Specific, Not Broad

Blocks only what needs blocking rather than using overly restrictive rules that prevent legitimate indexing.

Optimizes Crawl Budget

Directs crawlers to valuable content by blocking low-value pages, improving overall crawl efficiency and indexing speed.

Basic robots.txt Structure

Every robots.txt file follows a simple pattern. Understanding this structure is essential for creating effective rules.

The Three Core Elements:

1
User-agentSpecifies which crawler the rules apply to (Googlebot, Bingbot, etc.)
2
Disallow/AllowDefines which URLs or directories to block or permit
3
SitemapPoints to your XML sitemap location for better discovery

Basic Template:

User-agent: [bot name]
Disallow: [URL path]
Allow: [URL path]

Sitemap: [sitemap URL]

Minimal Working Example:

User-agent: *
Disallow:

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

This simple file allows all bots to crawl everything and points them to your sitemap.

User-Agent Rules Explained

The "User-agent" directive targets specific search engine crawlers. Each search engine uses different bots to crawl the web.

User-AgentSearch EnginePurpose
GooglebotGoogleMain web crawler
Googlebot-ImageGoogleImage search
BingbotBingMain Bing crawler
DuckDuckBotDuckDuckGoPrivacy-focused search
BaiduspiderBaiduChinese search engine

Block All Bots (Staging Sites):

User-agent: *
Disallow: /

Target Specific Bot:

User-agent: Googlebot
Disallow: /private/

Multiple Specific Bots:

User-agent: Googlebot
User-agent: Bingbot
Disallow: /admin/

Best Practice:

Start with User-agent: * for rules applying to all bots, then add specific rules for individual crawlers if needed.

Allow vs Disallow

Understanding when to use "Allow" versus "Disallow" is crucial for effective robots.txt management and SEO optimization.

Disallow Directive

Blocks access to specific URLs or directories.

Disallow: /folder/
Disallow: /page.html
Disallow: /*?parameter

Allow Directive

Explicitly permits access, overriding broader Disallow rules.

Disallow: /directory/
Allow: /directory/public/

Block Entire Directory:

User-agent: *
Disallow: /admin/

Block URLs with Parameters:

User-agent: *
Disallow: /*?
Disallow: /*?utm_*
Disallow: /*?ref=*

Allow Subdirectory Within Blocked Directory:

User-agent: *
Disallow: /admin/
Allow: /admin/css/
Allow: /admin/js/

Pattern Matching with Wildcards:

# Block all PDFs
Disallow: /*.pdf$

# Block URLs containing "session"
Disallow: /*session*

# Block all query parameters
Disallow: /*?*

* = matches any sequence | $ = matches end of URL

Adding Sitemap

Including your sitemap location in robots.txt helps search engines discover and index your content efficiently and improves overall SEO performance.

Sitemap Syntax:

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

Important Notes:

  • Use absolute URL - Always include full URL with https://
  • Can add multiple sitemaps - Include all relevant sitemap files
  • Case-sensitive - Must start with capital "S" in "Sitemap:"
  • Any location in file - Works anywhere (conventionally at end)

Multiple Sitemaps Example:

User-agent: *
Disallow: /admin/

Sitemap: https://www.example.com/sitemap.xml
Sitemap: https://www.example.com/sitemap-images.xml
Sitemap: https://www.example.com/sitemap-videos.xml
Sitemap: https://www.example.com/sitemap-news.xml

Sample SEO-Friendly robots.txt

Here's a comprehensive example for a typical business website following all SEO best practices:

# robots.txt for www.example.com
# Last updated: 2026-02-01

# Rules for all search engines
User-agent: *

# Block admin and private areas
Disallow: /admin/
Disallow: /login/
Disallow: /dashboard/
Disallow: /checkout/
Disallow: /cart/

# Block duplicate content
Disallow: /*?print=
Disallow: /*?sort=
Disallow: /*?filter=

# Block search results and pagination
Disallow: /search?
Disallow: /*?page=

# Allow important subdirectories
Allow: /admin/public/
Allow: /css/
Allow: /js/
Allow: /images/

# Block bad bots (optional)
User-agent: SemrushBot
User-agent: AhrefsBot
Disallow: /

# Crawl delay for specific bot (if needed)
User-agent: Bingbot
Crawl-delay: 2

# Sitemap locations
Sitemap: https://www.example.com/sitemap.xml
Sitemap: https://www.example.com/sitemap-products.xml

Common Mistakes

Avoid these frequent errors when creating your robots.txt file to prevent SEO disasters:

1. Blocking CSS and JavaScript

❌ Wrong:

User-agent: *
Disallow: /css/
Disallow: /js/

✅ Right:

User-agent: *
Allow: /css/
Allow: /js/

Why: Google needs CSS/JS to properly render and evaluate your pages. Blocking hurts rankings.

2. Syntax Errors

Common typos that break functionality:

  • user-agent: (should be User-agent)
  • disallow: (should be Disallow)
  • Dissalow: (typo)

3. Forgetting Trailing Slashes

❌ Wrong:

Disallow: /admin

Might not block /admin/ or /administrator

✅ Right:

Disallow: /admin/

Blocks /admin and all subdirectories

4. No Sitemap Reference

Always include your sitemap location. Missing sitemaps slow down discovery and indexing of your pages.

5. Wrong File Location

The robots.txt file MUST be in your root directory:

  • • ✓ https://www.example.com/robots.txt
  • • ✗ https://www.example.com/folder/robots.txt

Create Your robots.txt File Now

Use our free generator with built-in validation and SEO best practices

Buy Me a Coffee

If you find these tools helpful, consider supporting the project! Your support helps us maintain and improve our free tools for everyone.

Support Us