Write a robots.txt file to block folders

Description: Write a robots.txt for all bots which blocks the folders /admin/ and /tmp/, but allows the file /admin/help.html. Add the sitemap https://example.com/sitemap.xml.

Hint:

  • Use Disallow for blocked folders, Allow for the exception and Sitemap with the full address.

Solution

User-agent: *
Disallow: /admin/
Disallow: /tmp/
Allow: /admin/help.html

Sitemap: https://example.com/sitemap.xml
Test result of the rules above

Googlebot /admin/users Blocked
Googlebot /admin/help.html Allowed
Googlebot /tmp/cache.txt Blocked
Googlebot /about/ Allowed

How it works

  • The longer rule Allow: /admin/help.html wins over the shorter Disallow: /admin/ for that file.
  • The test shows that only the intended paths are blocked.

Read Robots.txt.


Learn more about the similar topics:
Tutorials
SEO – Canonical URLs
SEO – Robots.txt
SEO – XML Sitemap
Exercises & Assignments
Write a robots.txt file to block folders
Block all PDF files and URLs with a parameter in robots.txt
Add a canonical tag to a filtered page
Create an XML sitemap for three pages
Interview Questions & Answers
Which is more useful between an HTML sitemap and an XML sitemap?
What is technical SEO?
What is a robots.txt file?
What is an XML sitemap?
What is a canonical tag?
What is crawl budget?
What is duplicate content and how do you fix it?