Back to learning

The robots.txt file is a simple text file placed in the root directory of a website that provides instructions to web crawlers, such as search engine bots, about which parts of the website can or cannot be accessed, crawled, and indexed. The primary purpose of the robots.txt file is to help webmasters manage and control the crawling behavior of various bots, ensuring that they only access the desired sections of the website and conserve server resources.

The robots.txt file uses a basic syntax consisting of "User-agent" and "Disallow" (and sometimes "Allow") directives to communicate the desired crawling behavior to web crawlers.

Here's a detailed breakdown of the robots.txt file components:

  1. User-agent: This directive specifies the web crawler or bot that the following rules apply to. You can target specific bots (e.g., Googlebot, Bingbot) or use an asterisk (*) to apply the rules to all bots. Example:

    User-agent: Googlebot
    
  2. Disallow: This directive tells the web crawler not to crawl or access specific parts of the website, such as directories or individual pages. You can use a forward slash (/) to block the entire website or specify a particular path to block specific sections. Example:

    User-agent: Googlebot
    Disallow: /private/
    
  3. Allow (optional): This directive can be used in conjunction with the "Disallow" directive to grant access to specific files or subdirectories within a disallowed directory. This is particularly useful when you want to block a specific section of your website but still allow bots to access a few essential pages or resources. Example:

    Disallow: /private/ 
    Allow: /private/public-file.html
    

Here's an example of a complete robots.txt file:

User-agent: *
Disallow: /private/
Disallow: /temp/
Disallow: /cgi-bin/

User-agent: Googlebot
Disallow: /example-directory/
Allow: /example-directory/public-file.html

This robots.txt file has the following rules:

For all bots (User-agent: *), the "private," "temp," and "cgi-bin" directories are disallowed.

For Googlebot specifically, the "example-directory" is disallowed, but access to "public-file.html" within that directory is allowed. Keep in mind that the robots.txt file acts as a guideline for well-behaved bots, and there's no guarantee that all bots, especially malicious ones, will follow these rules. However, most major search engines and legitimate bots adhere to the robots.txt file directives to maintain a good relationship with webmasters and provide accurate search results.

Lastly, it is important to ensure that the robots.txt file is placed in the root directory of your website (e.g., https://www.example.com/robots.txt) so that web crawlers can easily locate and follow the instructions provided.

© PEAKHOUR.IO PTY LTD 2024   ABN 76 619 930 826    All rights reserved.