Home Blog Search Engine Optimization What is Robots.txt File & How to Create It?

What is Robots.txt File & How to Create It?

By Oyejobi Adeola | July 15, 2026 | 8 min read
What is Robots.txt

If you own a website, you’ve probably heard about the robots.txt file. While it may seem like a small technical file, it plays an important role in how search engines interact with your website.

A properly configured robots.txt file helps search engines understand which parts of your website they can crawl and which sections they should ignore. This can improve crawl efficiency, protect unnecessary pages from being crawled, and help search engines focus on your most important content.

In this guide, you’ll learn what a robots.txt file is, why it matters, how it works, how to create one, and common mistakes to avoid.

What is a Robots.txt File?

A robots.txt file is a plain text file placed in the root directory of your website. It gives instructions to search engine bots (also known as web crawlers or spiders) about which pages or folders they are allowed to crawl and which they should avoid.

When a search engine such as Google visits your website, one of the first files it checks is the robots.txt file.

For example:

https://yourwebsite.com/robots.txt

If the file exists, the search engine reads the instructions before crawling the rest of your website.

Keep in mind that robots.txt is only a set of instructions. Reputable search engines like Google and Bing obey these instructions, but malicious bots may ignore them.

Why is Robots.txt Important?

Although many websites can function without a robots.txt file, having one provides several benefits.

1. Improves Crawl Efficiency

Search engines allocate a crawl budget to every website. By blocking unnecessary pages, crawlers spend more time indexing your valuable content.

2. Prevents Crawling of Private Areas

You may not want search engines crawling areas such as:

  • Admin pages
  • Login pages
  • Shopping cart pages
  • Internal search pages
  • Temporary files

A robots.txt file helps discourage crawling of these sections.

3. Reduces Duplicate Content Issues

Some websites generate multiple URLs that display similar content. Blocking unnecessary versions helps search engines concentrate on the primary pages.

4. Protects Server Resources

Large websites often receive thousands of crawler requests daily. Limiting access to unnecessary sections reduces server load.

5. Helps Search Engines Find Your Sitemap

You can include your XML sitemap inside your robots.txt file, making it easier for search engines to discover all your important pages.

How Does Robots.txt Work?

The robots.txt file contains directives that tell crawlers what they can or cannot access.

The most common directives include:

User-agent

This specifies which search engine crawler the rule applies to.

Example:

User-agent: *

The asterisk (*) means the rule applies to all search engine bots.

Disallow

This tells crawlers not to visit a particular page or directory.

Example:

Disallow: /admin/

This prevents bots from crawling everything inside the admin folder.

Allow

This permits access to a specific file or folder even if its parent directory is blocked.

Example:

Allow: /images/logo.png

Sitemap

This tells search engines where your XML sitemap is located.

Example:

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

Basic Robots.txt Example

A simple robots.txt file may look like this:

User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php

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

This configuration:

  • Applies to all search engines
  • Blocks the WordPress admin folder
  • Allows the admin AJAX file
  • Provides the sitemap location

Where Should the Robots.txt File Be Located?

The robots.txt file must be placed in the root directory of your website.

Correct location:

https://example.com/robots.txt

Incorrect examples include:

https://example.com/files/robots.txt
https://example.com/blog/robots.txt

Search engines only look for the file in the root directory.

How to Create a Robots.txt File

Creating a robots.txt file is straightforward.

Step 1: Open a Text Editor

Use any plain text editor, such as:

  • Notepad
  • Notepad++
  • Visual Studio Code
  • Sublime Text

Avoid using Microsoft Word because it adds formatting.

Step 2: Write the Rules

Add the crawl instructions you want search engines to follow.

Example:

User-agent: *
Disallow:

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

An empty Disallow means all pages can be crawled.

Step 3: Save the File

Save it exactly as:

robots.txt

The filename should be lowercase.

Step 4: Upload to Your Website

Upload the file to your website’s root folder using:

  • cPanel File Manager
  • FTP software
  • Hosting File Manager
  • WordPress hosting dashboard

After uploading, verify by visiting:

https://yourwebsite.com/robots.txt

If the file appears, it has been uploaded correctly.

Robots.txt Example for WordPress

A common WordPress robots.txt file looks like this:

User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php

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

This is suitable for most WordPress websites.

Robots.txt Example for an E-commerce Website

Online stores often block unnecessary pages.

Example:

User-agent: *
Disallow: /cart/
Disallow: /checkout/
Disallow: /my-account/
Disallow: /search/

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

This keeps search engines focused on product and category pages.

Common Robots.txt Directives

Here are some of the most frequently used commands.

Allow Everything

User-agent: *
Disallow:

Block an Entire Website

User-agent: *
Disallow: /

Be extremely careful with this rule because it blocks all crawling.

Block One Folder

Disallow: /private/

Block One Page

Disallow: /thank-you.html

Block PDF Files

Disallow: /*.pdf$

Add Sitemap

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

Common Robots.txt Mistakes

Many website owners accidentally damage their SEO by making simple mistakes.

Blocking the Entire Website

This is one of the most serious errors.

Disallow: /

If this remains on a live website, search engines cannot crawl your pages.

Blocking Important CSS and JavaScript Files

Search engines need access to important resources to understand page layouts properly.

Avoid blocking:

  • CSS files
  • JavaScript files
  • Images required for rendering

Thinking Robots.txt Hides Sensitive Information

Robots.txt does not protect confidential data.

Anyone can visit:

yourwebsite.com/robots.txt

and see what you’ve blocked.

Sensitive information should be protected using passwords or server permissions.

Confusing “Noindex” with “Disallow”

Blocking a page in robots.txt does not automatically remove it from Google.

If a page is already indexed, it may continue appearing in search results.

Use proper indexing controls when necessary rather than relying solely on robots.txt.

How to Test Your Robots.txt File

Before using your robots.txt file, it’s important to verify that it works correctly.

You should check:

  • The file loads successfully
  • Important pages remain crawlable
  • Blocked pages are correctly restricted
  • The sitemap URL is accurate

Testing helps identify mistakes before they affect your website’s visibility.

Best Practices for Robots.txt

Follow these recommendations for optimal results.

  • Keep the file simple.
  • Only block pages that genuinely shouldn’t be crawled.
  • Include your XML sitemap.
  • Avoid blocking CSS and JavaScript unnecessarily.
  • Regularly review the file after website updates.
  • Test changes before deploying them.
  • Use lowercase filenames.
  • Place the file in the root directory.
  • Keep a backup before making edits.

When Should You Use a Robots.txt File?

A robots.txt file is beneficial if your website has:

  • WordPress admin pages
  • Internal search pages
  • Shopping cart pages
  • Duplicate URLs
  • Temporary folders
  • Large websites with thousands of pages
  • E-commerce platforms
  • Membership websites

Most websites can benefit from having a properly configured robots.txt file.

Frequently Asked Questions (FAQs)

What is the purpose of a robots.txt file?

A robots.txt file tells search engine crawlers which parts of your website they can crawl and which sections they should avoid. It helps improve crawl efficiency and manage how search engines interact with your site.

Where should the robots.txt file be placed?

It should be uploaded to the root directory of your website so it can be accessed at:

https://yourwebsite.com/robots.txt

Does robots.txt improve SEO?

Indirectly, yes. While it is not a ranking factor, it helps search engines use their crawl budget more efficiently by focusing on your important pages.

Can robots.txt hide confidential pages?

No. The robots.txt file is publicly accessible and should not be used to protect sensitive information. Use password protection or other security measures instead.

Can I have more than one robots.txt file?

No. A website should only have one robots.txt file located in the root directory.

What happens if my website doesn’t have a robots.txt file?

Search engines will generally crawl your website without restrictions. While this is acceptable for some sites, adding a robots.txt file gives you more control over crawling.

How do I know if my robots.txt file is working?

Visit https://yourwebsite.com/robots.txt in your browser to confirm the file is accessible, and test it using search engine webmaster tools to ensure the rules behave as expected.

Conclusion

A robots.txt file is a simple yet valuable part of technical SEO. It helps guide search engine crawlers, improves crawl efficiency, reduces unnecessary server load, and directs bots toward your most important content. Creating one only takes a few minutes, but configuring it correctly is essential—one incorrect directive can unintentionally block important pages from being crawled.

Whether you run a blog, business website, e-commerce store, or WordPress site, having a well-structured robots.txt file is a smart SEO practice. Review it regularly, keep it updated as your website evolves, and always test changes before publishing to ensure search engines can access the content that matters most.

Oyejobi Adeola

Article by

Oyejobi Adeola

Oyejobi Adeola is the founder of Nive Digital and NiveDigital Academy. With over 10 years of experience in SEO and digital marketing, he has helped businesses grow their online visibility, generate leads, and scale revenue through search engine optimization and digital marketing strategies. Adeola is passionate about simplifying SEO and helping Nigerians build profitable digital careers and businesses online..

View all posts
Career Guidance Banner
Career Counselling Banner
Image Popup