The robots.txt file, also known as the Robots Exclusion Protocol or Standard, is a simple text file used by websites to communicate with web crawlers and other web robots. It tells these crawlers which pages on the site should not be processed or scanned. This is primarily used to manage crawler traffic to avoid overloading the server and to keep certain parts of the website private.
robots.txt file must be placed in the root directory of the website.
example.com, the file should be located at https://example.com/robots.txt.User-agent: Specifies the web crawler the rule applies to.Disallow: Tells the crawler not to access certain parts of the site.Allow: (Optional) Overrides a Disallow rule for specific URLs.Crawl-delay: (Optional) Specifies the delay between successive requests to the server.Sitemap: (Optional) Provides the location of the website’s XML sitemap.Here is an example of a robots.txt file with some common commands:
User-agent: *
Disallow: /private/
Disallow: /tmp/
Allow: /public/
Crawl-delay: 10
Sitemap: https://example.com/sitemap.xml
*) indicates that the rules apply to all web crawlers.User-agent: GooglebotDisallow: /private/Disallow rule exists.Allow: /public/Crawl-delay: 10Sitemap: https://example.com/sitemap.xmlConsider a website with the following robots.txt file:
User-agent: *
Disallow: /admin/
Disallow: /login/
Allow: /public/
Crawl-delay: 5
User-agent: Googlebot
Disallow: /no-google/
Allow: /google-allowed/
Crawl-delay: 10
Sitemap: https://example.com/sitemap.xml
*):
/admin/ and /login/ directories./public/ directory./no-google/ directory./google-allowed/ directory.robots.txt file is case-sensitive, so be careful with directory and file names.robots.txt file and ensure it’s working as expected.robots.txt is publicly accessible, so don’t use it to hide sensitive information.By properly configuring the robots.txt file, website administrators can control which parts of their site are accessible to web crawlers, optimizing the site's performance and security.