Robots.txt

If you want to control how search engines crawl your website, the robots.txt file will be your most powerful ally. It is a critical tool that defines which parts of your website search engines are allowed to crawl and which are off limits.
What Is a Robots.txt File?
Robots.txt is a text file placed in the root directory of your website that tells search engine bots (crawlers) which pages they may crawl. It works according to the Robots Exclusion Protocol standard and has been an indispensable part of the web since 1994.
Why Should You Use Robots.txt?
For SEO Performance: By keeping unnecessary pages from being crawled, it lets search engines use your crawl budget more efficiently.
Privacy and Security: It keeps bots away from sensitive areas such as admin panels and development environments.
Site Speed: It improves server performance by reducing unnecessary bot traffic.
Content Quality: It helps keep low-quality or duplicate content out of the crawl.
How to Create a Robots.txt File
1. Creating and Placing the File
You can use any text editor to create a robots.txt file:
# Robots.txt example
User-agent: *
Disallow: /admin/
Disallow: /private/
Allow: /public/
Crawl-delay: 10
Sitemap: https://example.com/sitemap.xml
Key point: The file must be placed in your site's root directory (example.com/robots.txt).
2. Basic Directives and Their Meanings
User-agent: Specifies which bots the rules apply to
*= All botsGooglebot= Google's bot onlyBingbot= Bing's bot only
Disallow: Blocks crawling of the specified directories or files
Disallow: /admin/ # Block the admin folder
Disallow: /search? # Block search results
Disallow: /*.pdf$ # Block PDF files
Allow: Grants specific exceptions within a broader block
User-agent: *
Disallow: /private/
Allow: /private/public-info/
Crawl-delay: Sets the wait time (in seconds) between bot requests. Note that Google ignores this directive, while some other search engines respect it.
Crawl-delay: 10 # Wait 10 seconds
Sitemap: Specifies the location of your XML sitemap file
Sitemap: https://example.com/sitemap.xml
Sitemap: https://example.com/news-sitemap.xml
Practical Examples and Use Cases
Robots.txt for an E-Commerce Site
User-agent: *
Disallow: /cart/
Disallow: /checkout/
Disallow: /account/
Disallow: /admin/
Disallow: /search?
Disallow: /*?sort=
Disallow: /*?filter=
Allow: /
Crawl-delay: 5
Sitemap: https://example.com/sitemap.xml
Robots.txt for a Blog
User-agent: *
Disallow: /wp-admin/
Disallow: /wp-content/plugins/
Disallow: /wp-content/themes/
Disallow: /author/
Disallow: /tag/
Allow: /wp-content/uploads/
Crawl-delay: 2
Sitemap: https://example.com/sitemap.xml
Robots.txt for a Corporate Website
User-agent: *
Disallow: /internal/
Disallow: /staff/
Disallow: /development/
Disallow: /test/
Allow: /
Crawl-delay: 3
Sitemap: https://example.com/sitemap.xml
Professional Tips for the Right Structure
1. Mind the Syntax Rules
- Each line should be a separate directive
- Paths are case-sensitive
- Whitespace matters
- Comments must start with
#
2. Don't Forget to Test
Test your file with the "robots.txt Tester" tool in Google Search Console. It helps you detect syntax errors and logical problems.
3. Security Considerations
Wrong: Listing sensitive directories in robots.txt
Disallow: /secret-admin-panel/ # This is a security risk!
Right: Protect sensitive areas at the server level and don't list them in robots.txt
4. Performance Optimization
- Use general rules instead of very specific ones
- Don't set unnecessary crawl-delay values
- Always specify the sitemap location
5. Common Mistakes and Fixes
Mistake 1: Blocking the entire site
# Wrong
User-agent: *
Disallow: /
Mistake 2: Confusing it with noindex. Robots.txt only blocks crawling, not indexing. Use a meta tag to prevent indexing.
Mistake 3: Conflicting rules for different bots
# Conflicting
User-agent: *
Disallow: /admin/
User-agent: Googlebot
Allow: /admin/
Separating Mobile and Desktop Bots
User-agent: Googlebot
Disallow: /mobile-app/
User-agent: Googlebot-Mobile
Allow: /mobile-app/
Disallow: /desktop-only/
Advanced Wildcard Usage
User-agent: *
Disallow: /*?sessionid= # All URLs with a session ID
Disallow: /*?utm_* # URLs with UTM parameters
Disallow: /*.json$ # JSON files
Disallow: /*/print/ # Print pages
Monitoring and Maintenance
Regular Checklist
- Monthly: Check for robots.txt errors in Google Search Console
- Quarterly: Update the rules for newly added sections
- Yearly: Align your robots.txt strategy with your overall SEO strategy
Analysis Metrics
- Crawl budget usage
- Number of indexed pages
- Organic traffic changes
- Sitemap coverage rate
Conclusion
The robots.txt file is one of the core tools that govern your website's relationship with search engines. Configured correctly, it improves your SEO performance; used incorrectly, it can cause serious problems. By adapting the examples in this guide to your own site's needs, you can create a robots.txt file optimized for search engines.
Remember, robots.txt is only a starting point. It should be used as part of a comprehensive technical SEO strategy. Test it regularly, update it, and let your robots.txt file evolve alongside your website.
Koray Çamdalı