What is Robots.txt?
The robots.txt file is a text file that tells search engines which pages or sections of a website they can crawl and which ones they should avoid. It is an essential part of the robots exclusion protocol and helps optimize the indexing of your website, preventing unnecessary or private content from being accessed by search engine bots.
What is the Robots.txt file for?
The robots.txt file is essential for managing the SEO and security of a website. Its main uses include:
- Controlling search engine access: You can restrict parts of your site that you don’t want to be indexed.
- Optimizing bot crawling: Prevents search engines from wasting resources on irrelevant content.
- Protecting sensitive information: While not a definitive security measure, it does help prevent private files from being indexed.
- Indicating the location of your sitemap: Helps search engines find important URLs more quickly.
Where to find your Robots.txt file
The robots.txt file should be located at the root of your website’s domain. For example:
https://www.yourdomain.com/robots.txt
If you try to access this URL and the file exists, you can see it in your browser.
How to Create a Robots.txt File
If your website doesn’t have a robots.txt, you can create one manually using any text editor such as Notepad, Visual Studio Code, or the built-in editor in cPanel. Then, just upload it to your server’s root folder.
Basic Structure of a Robots.txt File
A basic robots.txt typically includes rules to allow or block access to certain parts of the site. Its structure is as follows:
User-agent: *
Disallow: /private/
Allow: /public/
Sitemap: https://www.yourdomain.com/sitemap.xml
- User-agent: Specifies which bots the rules affect. The asterisk (*) indicates that the rule applies to all search engines.
- Disallow: Blocks access to specific directories or files.
- Allow: Allows access to certain parts of the site.
- Sitemap: Indicates the location of the sitemap.xml to improve indexing.
Examples of Robots.txt Configurations
Block Access to the Entire Site
User-agent: *
Disallow: /
This file prevents any search engine from indexing the website.
Allow Full Access to the Entire Site
User-agent: *
Disallow:
Bots can crawl all pages on the site.
Block a Specific Directory
User-agent: *
Disallow: /admin/
Prevents search engines from accessing the /admin/ directory.
Block a Specific File
User-agent: *
Disallow: /secret.html
Prevents the secret.html file from being indexed.
Block a Specific User-Agent
User-agent: Googlebot
Disallow: /
Prevents Googlebot from crawling the site, but allows access to other search engines.
How to Optimize Robots.txt in WordPress
If you use WordPress, you can manage and optimize the robots.txt file in several ways:
1. Edit Robots.txt from within WordPress
Some SEO plugins allow you to edit the file directly from the WordPress admin panel. One of the most recommended is Yoast SEO. To edit it:
- Install and activate the Yoast SEO plugin.
- Go to SEO > Tools.
- Select File Editor.
- Edit the robots.txt file according to your needs and save the changes.
2. Using Plugins to Generate an Optimal Robots.txt
Other useful plugins to manage robots.txt in WordPress are:
- Rank Math SEO: Provides advanced options to configure the robots.txt.
- All in One SEO Pack: Allows you to modify the file without accessing the server.
3. Editing the Robots.txt File Manually
If you prefer to edit it directly on the server:
- Access your server via FTP or cPanel.
- Locate the robots.txt file in the root of your site.
- Download it, edit it with a text editor, and upload it again.
4. Recommended WordPress Settings
A WordPress-optimized robots.txt file might look like this:
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Disallow: /wp-includes/
Disallow: /wp-content/plugins/
Disallow: /wp-content/themes/
Disallow: /?s=
Sitemap: https://www.yourdomain.com/sitemap_index.xml
- Disallow: /wp-admin/: Prevents bots from accessing the admin panel.
- Allow: /wp-admin/admin-ajax.php: Allows AJAX access for proper site operation.
- Disallow: /wp-includes/: Blocks internal WordPress files.
- Disallow: /wp-content/plugins/ and /wp-content/themes/: Prevents bots from crawling plugin and theme files.
- Disallow: /?s=: Prevents indexing for internal WordPress searches.
- Sitemap: Indicates the URL of the XML sitemap to improve indexing.
Checking and Validating the Robots.txt File
To make sure it works correctly, you can use tools like:
- Google Search Console – Robots.txt Tester
- SEO audit tools like Screaming Frog or Ahrefs.
Best Practices When Using Robots.txt
To ensure that the robots.txt is effective, follow these recommendations:
- Avoid blocking CSS and JavaScript: Google needs these files to render the web correctly.
- Don’t use Robots.txt to hide sensitive information: It’s better to protect pages with passwords or server-side settings.
- Don’t overuse Disallow: Blocking too many pages can hurt SEO.
- Use the Sitemap directive: It makes it easier for important URLs to be indexed.
- Review your file periodically: Google changes its algorithms, and what works today may become obsolete.
Conclusion
The robots.txt file is a powerful tool for managing search engine crawling of your website. Proper configuration helps improve SEO and bot crawling efficiency by ensuring that only relevant content is indexed. At ALHOSTINGS, we can help you optimize your robots.txt and improve your SEO strategy. Contact me!

WordPress Expert, SEO & UX Optimization | I help freelancers and SMEs grow their business. | Web Design and Development Specialist for Startups, SMEs, and Personal Projects