What is Robot.txt File

Table of Contents

Robots.txt File - Everything to know about

The robots.txt file placed in the root of a website tells search engine crawlers which URLs the crawler can access on your site. Sitemap. Using a no-index tag, can block Google crawlers from indexing the website.

If you want to hide or unhide one of your pages from search engines, search for specific instructions as per the CMS you are working with.

If your web page is blocked with a robots.txt file, its URL can still appear in search results without a description. Image files, video files, PDFs, and other non-HTML files will be excluded. If you see this search result for your page and want to fix it, remove the robots.txt entry blocking the page.

If you want to hide the page completely from Search, you may use the Google Search Console Removals tool to remove a page hosted on your site from Google search results within a day.

In a nutshell - Robots.txt file Definition

Website owners use the /robots.txt file to give instructions about their site to web robots.

It works like this: a robot wants to vist a Web site URL, say https://www.ZabiNiazi.com/SEO, Before it does so, it firsts checks for ZabiNiazi.com/robots.txt, and finds:

User-agent: *
Disallow: /

The “User-agent: *” means this section applies to all robots. The “Disallow: /” tells the robot that it should not visit any pages on the site.

Robots.txt Tips

  •  Test your robots.txt file with the Google Search Console robots.txt tool
  • Prevent search engines from crawling duplicate content, like PDFs, with your robots.txt file
  • Use your robots.txt file to direct crawlers to your XML sitemap

Robots.txt file Considerations

There are two important considerations when using /robots.txt:

  • Robots can ignore your /robots.txt. Especially malware robots that scan the web for security vulnerabilities, and email address harvesters used by spammers will pay no attention.
  • The /robots.txt file is a publicly available file. Anyone can see what sections of your server you don’t want robots to use, suggest not using/robots.txt to hide information.
Robots.txt File

How to create a /robots.txt file & Where to put

The short answer: is in the top-level directory of your web server.

The longer answer:

When a robot looks for the “/robots.txt” file for the URL, it strips the path component from the URL (everything from the first single slash), and puts “/robots.txt” in its place.

For example, for “abc.com/shop/index.html, it will remove the /shop/index.html“, and replace it with “/robots.txt“, and will end up with abc.com/robots.txt”.

So, as a website owner, you need to put it in the right place on your web server for that resulting URL to work. Usually, that is the same place where you put your website’s main “index.html” welcome page. Where exactly that is, and how to put the file there, depends on your web server software.

Remember to use all lowercase for the filename: “robots.txt“, not “Robots.TXT.

What to Include in a Robots.txt File

The “/robots.txt” file is a text file, with one or more records. Usually contains a single record looking like this:

User-agent: *
Disallow: /cgi-bin/
Disallow: /tmp/
Disallow: /~zabi/

In this example, three directories are excluded.

Note that you need a separate “Disallow” line for every URL prefix you want to exclude — you cannot say “Disallow: /cgi-bin/ /tmp/” on a single line. Also, you may not have blank lines in a record, as they are used to delimit multiple records.

Note also that globbing and regular expression are not supported in either the User-agent or Disallow lines. The ‘*’ in the User-agent field is a special value meaning “any robot”. Specifically, you cannot have lines like “User-agent: *bot*”, “Disallow: /tmp/*” or “Disallow: *.gif”.

What you want to exclude depends on your server. Everything not explicitly disallowed is considered fair game to retrieve. Here follow some examples:

To exclude all robots from the entire server
User-agent: *
Disallow: /
To allow all robots complete access
User-agent: *

(or just create an empty “/robots.txt” file, or don’t use one at all)

To exclude all robots from part of the server
User-agent: *
Disallow: /cgi-bin/
Disallow: /tmp/
Disallow: /junk/
To exclude a single robot
User-agent: BadBot
Disallow: /
To allow a single robot
User-agent: Google
User-agent: *
Disallow: /
To exclude all files except one

This is currently a bit awkward, as there is no “Allow” field. The easy way is to put all files to be disallowed into a separate directory, say “stuff”, and leave the one file in the level above this directory:

User-agent: *
Disallow: /~zabi/stuff/

Alternatively, you can explicitly disallow all disallowed pages:

User-agent: *
Disallow: /~zabi/junk.html
Disallow: /~zabi/foo.html
Disallow: /~zabi/bar.html

About the Author

Zabi Niazi - Director of Search Marketing SEM and SEO

Hands-on execution & Revenue-focused digital marketer with expertise in Design & Operations centered around people, processes & technology engineering a Demand-Gen Engine capable of delivering innovative experiences that tell the brand story and map to the buyer's journey generating awareness, acquisition, retention, and advocacy.