Using robots.txt to disallow search engines to index your files

Source

As a writer who contributes articles to various sites around the internet, I wanted to set up an online archive for my work. This would be a repository to which I could give others access as needed (for example, to establish authorship in copyright infringement cases). At the same time, to avoid having different references to the same material show up in search results, I needed to prevent the files in my archive from being indexed by search engines such as Google or Bing.

A little research showed that by using a robots.txt file, I could inform search engines that they should not index certain items on my website. It’s a simple and easy solution that does exactly what I need it to do. But in setting up my robots.txt file, I ran into some issues that were not addressed in the documentation I had read, and which required some time and head-scratching to figure out through trial and error.

That’s why I thought it might be useful to provide a simple guide that might save someone else from having to struggle with the issues I did.

Source

What is robots.txt?

Search engines use applications called “robots” to “crawl” the entire internet, searching out online files and adding them to a database. When a user enters a search term into Google, for example, that query is matched against Google’s database of websites it has crawled. It is from that internal database that a list of search results is produced for the user.

The robot.txt file is used to essentially put up a KEEP OUT sign for files on your website you don’t want search engine robots to see. Since these files will be skipped by the robot, they won’t be indexed in the search engine’s database, and they won’t show up in search results.

Reputable search engines all program their robots to look for the robot.txt file on every website they find. If that file exists, the robot will follow its instructions regarding any files or folders the robot should skip.

(Take note that this is all entirely voluntary on the search engine’s part. Rogue search engines can and do ignore the instructions in robot.txt. In fact, some bad guys may actually be attracted to the parts of your website robot.txt says to avoid on the theory that if you want to hide it, there might be something there they can exploit).

How to set up a robots.txt file

I’m going to describe how I set up my robots.txt file to address my specific need. You can read a more general description of the various ways robots.txt can be used here.

First of all, to use a robots.txt file you must have access to the top level directory of your web site. That’s where the robots.txt file will be placed.

For example, if your web site is

http://www.myownwebsite.com

then the robots.txt file must have the name

http://www.myownwebsite.com/robots.txt

Note that if you put robots.txt anywhere else on the site, it won’t be recognized. For example, if you put your robots.txt into a folder called mygoodstuff:

http://www.myownwebsite.com/mygoodstuff/robots.txt

web crawling robots will not recognize it, and won’t heed its instructions.

Also note that capitalization matters! The file name must be robots.txt and nothing else. ROBOTS.TXT or Robots.Txt won’t work.

Do you plan to personally set up a robots.txt file?

  • Yes - I think I can set one up with few problems
  • No - I'm too concerned that I might mess something up
  • No - But I have someone I trust to do it for me
See results without voting

The contents of a robots.txt file

Here’s what the contents of a typical robots.txt file might look like:

User-agent: *

Disallow: /folder-to-ignore/

The User-agent term specifies the particular search engines to which this directive is addressed. The * in the above example signifies that it applies to all search engines. If you only want your instructions to apply to Google, for example, you would use:

User-agent: Google

Disallow: /folder-to-ignore/

This would restrict only Google, and not any other search engines, from accessing the folders or files you list.

The Disallow term specifies which folders or files are not to be searched or recognized by the robot. In the example above, I don't want the contents of a folder called folder-to-ignore to be indexed by search engines. So, my Disallow statement instructs web crawlers to ignore the following URL:

http://www.myownwebsite.com/folder-to-ignore/

Multiple folders or files can be specified:

User-agent: *

Disallow: /folder-to-ignore/

Disallow: /another-folder/

Disallow: /third-folder/subfolder/

Disallow: /some-folder/myfile.html

Creating a robots.txt file

Any text editor, such as NotePad in Windows, may be used to create robot.txt files. Note that if a document editor, such as Microsoft Word, is used, the output must be saved as a .txt file. Otherwise, the file may contain hidden codes that will invalidate its contents.

Once saved as text, the file must be uploaded to the top level directory of your website. On most servers, that will be the public_html folder.

Upload robots.txt in exactly the same way you normally upload files to the site, making sure it is placed in the proper folder.

VIDEO: How to create a robots.txt file

Testing your robots.txt file

It’s very important to test your robots.txt setup to insure that it’s working as you desire. Otherwise you may find that the folders you wanted blocked are still accessible to crawlers, and are showing up in search results. Once that happens, it could take weeks or even months to get them removed from the search engine’s database.

Several free robots.txt testers are available on the web. Here are the ones I used:

Google’s Webmaster Tools robots.txt tester (requires a Google account)

http://www.searchenginepromotionhelp.com/m/robots-text-tester/robots-checker.php

The GOTCHAs that got me!

Google was unable to see my robots.txt file

I set up my robots.txt file to block a folder called /YCN Archive/. I created that folder on my website and verified that it could be accessed as expected.

I then created a robots.txt file with the following contents:

User-agent: *

Disallow: /YCN Archive/

After uploading this file to my top-level directory, I tested it using the robots.txt tester in Google’s Webmaster Tools. Although I carefully followed the directions given via the Webmaster Tools link above, I immediately ran into a problem. Here’s the totally unexpected error message I got:

But the robot.txt was there! I could see it in my website’s file listing, exactly where it was supposed to be. Why couldn’t Google see it? Eventually I saw something on the tester page I hadn’t noticed before:

The key was in the line that says, “Latest version seen on 7/26/14 …” (I was doing the test several days after 7/26). When I initiated the test, it seems that Google didn’t go out and look at the state of the website at that moment, but apparently relied on its internal picture of what the website looked like the last time it crawled it.

I needed Google to have a current picture of what was on my website. I caused that to happen by using the Fetch as Google function:

Once the Fetch as Google function was performed, Google was able to find the robots.txt file.

Here’s another point to be careful of. In the robots.txt tester, Google listed my website two different ways:

covcommchurch.org

http://covcommchurch.org

Of course both those entries refer to exactly the same URL. But I had to do individual Google fetches for each to have the robots.txt file recognized. I also did separate tests on each in order to make sure my blocking instructions would be carried out no matter which URL was used to access the site.

My robots.txt file didn’t work!

Now that Google could see my robots.txt file, I ran the test, confident of success. It still didn’t work. This time, the test reported that although my robots.txt was now recognized, it was not blocking access to the /YCN Archive/ folder. Web crawler access to that folder was still "ALLOWED."

No spaces allowed in the disallowed folder or file’s name

I knew my robots.txt was set up correctly, so it baffled me why it was not blocking access to the specified folder. It took me some time to figure out what was going on. My folder had a space in the name! When I renamed the folder to remove the space, the Google robots.txt tester showed the folder as blocked.

robots.txt does its job

Since I put my robot.txt in place, it’s done its job silently and efficiently. My files are safely archived online, and can be accessed by anyone to whom I give the URL. But none of them are showing up in search engine results.

© 2014 Ronald E. Franklin

More by this Author


6 comments

RachaelOhalloran profile image

RachaelOhalloran 2 years ago from United States

This is great information. I can't use it here on HubPages, but I can use it on my blogs. Thanks!


RonElFran profile image

RonElFran 2 years ago from Mechanicsburg, PA Author

Thanks, Rachael. Interestingly, while setting up my website's robots.txt, I also looked in Google Webmaster Tools at the robots.txt of my HubPages subdomain. It's there, though of course we don't have access to change it.


Mel Carriere profile image

Mel Carriere 2 years ago from San Diego California

I don't think I see the need to do this at this point. I'm busy at this juncture trying to get search engines to find me more. Nonetheless this is great info to store for future use and it was very competently presented!


RonElFran profile image

RonElFran 2 years ago from Mechanicsburg, PA Author

Thanks, Mel. Actually this was prompted by the Yahoo Voices shutdown, plus the need to have proof of authorship of many of my Yahoo articles that had been pirated. So, a writer may suddenly need this kind of info at any time.


kislanyk profile image

kislanyk 2 years ago from Cyprus

I used this trick all the time and on some of my sites I tweak it as I go alone (in my cPanel). Great tip!

Btw something I've noticed recently - if you have a Wordpress blog, the robots.txt file is virtual, meaning it doesn't actually exist. Too me quite some time to figure it out once when I needed to change...kind of sucked, but oh well...


RonElFran profile image

RonElFran 2 years ago from Mechanicsburg, PA Author

Hi, kislanyk. It's interesting about Wordpress. I looked at my Wordpress robots.txt, but didn't realize it's virtual. For me that's fine; I wasn't wanting to change it anyway. Thanks for reading and sharing.

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working