Search engine crawlers index websites regardless of the presence of robots.txt and sitemap.xml. However, using a robots.txt file allows webmasters to specify what should be excluded from indexing and to configure other important parameters.
It is important to note that search engine crawlers may ignore certain rules. For instance:
Directives are rules for robots. There is a W3C specification from January 30, 1994, and an extended standard from 1996.
User-agent: This directive begins the robots.txt file.
Example:
User -agent: * # instructions for all search engine robots. User -agent: GoogleBot # instructions for Google’s robot. Disallow: / # disallow directive, prohibits indexing of what follows. Allow: / # allow directive, specifies URLs to be indexed. Disallow: # does not work without the special character /. Allow: / # ignored if no URL follows /.
Be cautious with the character /; a common mistake is:
User -agent: * Disallow: / # this will block the entire site from indexing.
The special character * represents any character sequence, including an empty one. For example:
Disallow: /cart/* # blocks all pages following the URL: site.com/cart/
The special character $ restricts the action of the character *, providing strict limitations:
User -agent: * Disallow: /catalog$ # with this character, catalog will not be indexed, but catalog.html will be.
The sitemap directive specifies the path to the sitemap and looks like this:
User -agent: * Allow: / Sitemap: http://www.site.com/sitemap.xml # must be specified with http:// or https://, use https:// if an SSL certificate is installed.
The Host directive indicates the main mirror of the website with or without www.
User -agent: * Allow: / Sitemap: http://www.site.com/sitemap.xml Host: www.site.com # specify the domain path without http and slashes.
The Crawl-Delay directive limits server load by setting a timeout for search engines:
User -agent: * Crawl-delay: 2 # sets a timeout of 2 seconds. User -agent: * Disallow: /search Crawl-delay: 4.5 # sets a timeout of 4.5 seconds.
The Clean-Param directive is necessary if page addresses contain dynamic parameters that do not affect the content, such as session IDs, user IDs, referrers, etc.
Using the Clean-Param directive, search engines will avoid repeatedly crawling duplicate information, improving the efficiency of your website's crawling and reducing server load.
For example, pages with the following addresses:
www.site.com/some_dir/get_book.pl?ref=site_1&book_id=123 www.site.com/some_dir/get_book.pl?ref=site_2&book_id=123 www.site.com/some_dir/get_book.pl?ref=site_3&book_id=123
The ref parameter is used solely to track which resource made the request and does not change the content. All three addresses will display the same page with book_id=123. So, if the directive is specified as follows:
User -agent: * Disallow: Clean-param: ref /some_dir/get_book.pl
The search engine will consolidate all page addresses into one:
www.site.com/some_dir/get_book.pl?ref=site_1&book_id=123,
It’s worth noting that there are several options for configuring this directive.
Using characters from the Russian alphabet is prohibited in robots.txt; Punycode must be used (a standardized method for converting Unicode character sequences into ACE sequences).
#Incorrect: User -agent: * Disallow: /basket Host: internet-store.com #Correct: User -agent: * Disallow: /basket Host: https://internet-store.com
Utilize various online tools to check for errors in your robots.txt file.
Keep in mind that a file larger than 32 KB is read as fully allowing, regardless of its content.
Excessive filling of robots.txt. New webmasters may be impressed by articles stating that everything unnecessary must be blocked in robots.txt and begin to block almost everything except text on specific pages. This is, to put it mildly, incorrect. First, there is a recommendation not to block scripts, CSS, and other elements that may prevent the bot from seeing the site as a user does. Secondly, many errors arise from blocking one thing, which inadvertently blocks another. It is advisable to check the accessibility of a page and its elements. A common mistake is the confusion between Allow and Disallow directives. It is best to block only clearly unnecessary items for the bot, such as registration forms and redirect pages, while using canonical tags to eliminate duplicates. Note that correcting robots.txt does not mean that search engine bots will read it immediately. To expedite this process, check your robots.txt in the webmaster section.
Examples of properly configured robots.txt for different CMS:
User -Agent: * Allow: /wp-content/uploads/ Disallow: /wp-login.php Disallow: /wp-register.php Disallow: /xmlrpc.php Disallow: /template.html Disallow: /wp-admin Disallow: /wp-includes Disallow: /wp-content Disallow: /tag Disallow: /category Disallow: /archive Disallow: */trackback/ Disallow: */feed/ Disallow: */comments/ Disallow: /?feed= Disallow: /?s= Host: site.com Sitemap: http://site.com/sitemap.xml
User -agent: * Disallow: /manager/ Disallow: /assets/components/ Disallow: /core/ Disallow: /connectors/ Disallow: /index.php Disallow: *? Host: example.com Sitemap: http://example.com/sitemap.xml
User -agent: * Disallow: /*route=account/ Disallow: /*route=affiliate/ Disallow: /*route=checkout/ Disallow: /*route=product/search Disallow: /index.php?route=product/product*&manufacturer_id= Disallow: /admin Disallow: /catalog Disallow: /download Disallow: /export Disallow: /system Disallow: /*?sort= Disallow: /*&sort= Disallow: /*?order= Disallow: /*&order= Disallow: /*?limit= Disallow: /*&limit= Disallow: /*?filter_name= Disallow: /*&filter_name= Disallow: /*?filter_sub_category= Disallow: /*&filter_sub_category= Disallow: /*?filter_description= Disallow: /*&filter_description= Disallow: /*?tracking= Disallow: /*&tracking= Disallow: /*?page= Disallow: /*&page= Disallow: /wishlist Disallow: /login Disallow: /index.php?route=product/manufacturer Disallow: /index.php?route=product/compare Disallow: /index.php?route=product/category
User -agent: * Allow: /index.php?option=com_xmap&sitemap=1&view=xml Disallow: /administrator/ Disallow: /cache/ Disallow: /components/ Disallow: /go.php Disallow: /images/ Disallow: /includes/ Disallow: /installation/ Disallow: /language/ Disallow: /libraries/ Disallow: /logs/ Disallow: /media/ Disallow: /modules/ Disallow: /plugins/ Disallow: /templates/ Disallow: /tmp/ Disallow: /xmlrpc/ Disallow: /*com_mailto* Disallow: /*pop=* Disallow: /*lang=en* Disallow: /*format=* Disallow: /*print=* Disallow: /*task=vote* Disallow: /*=watermark* Disallow: /*=download* Disallow: /*user/* Disallow: /.html Disallow: /index.php? Disallow: /index.html Disallow: /*? Disallow: /*% Disallow: /*& Disallow: /index2.php Disallow: /index.php Disallow: /*tag Disallow: /*print=1 Disallow: /trackback Host: yoursite.com