Disallow Robots Using Robots.txt

Written by David Walsh on July 3, 2009 · 24 Comments

I develop customer websites on a publicly accessible web server so that my customers may check the progress of their website at any given time. I could use .htaccess to require username and password for the site but then I'm constantly needing to remind customers what their password is. My big concern is preventing search engines from finding their way to my development server. Luckily I can add a robots.txt file to my development server websites that will prevent search engines from indexing them.

The Robots.txt

User-agent: *
Disallow: /

The above directive prevents the search engines from indexing any pages or files on the website. Say, however, that you simply want to keep search engines out of the folder that contains your administrative control panel. You'd code:

User-agent: *
Disallow: /administration/

Or if you wanted to allow in all spiders except Google's GoogleBot, you'd code:

User-Agent: googlebot
Disallow: /

What would you prevent the search engines from seeing?

Comments

  1. Evan Riley July 3, 2009

    Sweet! Now I can block all the back-up’d pronz :p

  2. Nice article David, but we must be extra careful not to block Google from legit content!

  3. There is one small problem with this. robot.txt is often a hotlist for hackers. If someone wants to hack your site, robot.txt shows them all the best spots.

  4. When I was getting my blog ready, Google somehow found my public testing server (which was hosted in my basement no less) and decided to index a couple of my test posts. I have used Perishable Press’ User Agent Blacklist since then and for the most part bots haven’t broken through.
    (Sorry if this posted twice, I submitted the first time but it seems that wp-post timed out.)

  5. Binny V A: Good point. I believe a nice .htaccess hack would take care of that.

  6. As I understand it, the robots.txt file doesn’t actually prevent search engines from indexing you, it just tells them not to. If they want to index you they can just ignore the file.
    http://www.robotstxt.org/faq/blockjustbad.html
    Mike

  7. Binny is correct… but that shouldn’t stop you from using robot.txt!
    I block all my cms folders and private stuff using robot.txt

    Hey David, How can you protect the file using .htaccess ? I believe this will block the searchbots too right?

  8. digital July 5, 2009

    Maybe this would help:

    <Files robots.txt>
    order allow,deny
    deny from all
    </Files>

  9. Aren’t you relying on spider programs actually following the rules? What prevents someone from writing a spider which ignores your robots.txt file and actually indexing your entire site?

  10. It appears some are thinking this post is about how to secure your site …

  11. Mike V - RaleighNC July 8, 2009

    @Binny VA, there’s no reason you can’t sprinkle in a few random directories to mislead your hacker audience. A little light security by obscurity.

    User-agent: *
    Disallow: /adm/
    Disallow: /administration/
    Disallow: /admin/
    Disallow: /adminportal/
    Disallow: /drupal/
    Disallow: /joomla/

  12. Thank you, Ive been looking for this info for 3 hours now.

  13. Ryan’s correct, this post isn’t about securing your site.

  14. I had never considered doing a .htaccess hack to exclude items. What a marvelous idea!

    Thanks for that. I am going to work on implementing it ASAP.

  15. If you block the robots.txt file using .htaccess rules, not only the hackers wouldn’t be able to read it, but also the search bots. That means it’s useless to do it – it would be easier to simply delete robots.txt in that case.

  16. Hi, I need to know how to block ROBOTS.txt using HTACCESS, means I want to block robots.txt from spiders but from htaccess.

  17. One should be careful not to rely on robots.txt as a means of security. It offers no security.
    The robots.txt file is only a directive to cooperating web crawlers/bots on what to index. The file(s) you’re trying to restrict the access of are still publicly accessible.

    If you don’t want a part of your website to be publicly accessible then password protect it.

  18. It was really helpful… thanks

  19. i want to disallow google from my site . please can you write a code ?

    or this one is enough

    User-agent: *
    Disallow: /

  20. Yes that will be sufficient to block all cooperative crawlers (Google included).

  21. This is really helpful for me. is it any hermful for my alexa rank and PR?

  22. This was helpful, I want search engines to not to crawl my wordpress archive pages, admin pages and upload pages… how can I do that?
    Thanks.

  23. Thanks for this. Been looking for this kind of solution for my directory site. It will help me save bandwith.

  24. Hello,

    Recently I moved to new host and I got a temporary URL for testing purpose. I did a search with my site name, google is showing both the temp url and original url. I want to remove the temp url completely. This is my temporary URL digitaladvices.com.cp-21.webhostbox.net. How can I block this url using robots.txt file? or any other possible ways?

Be Heard

Tip: Wrap your code in <pre> tags or link to a GitHub Gist!

Use Code Editor
Older
Reduce PNG Graphic Size Using PNGCRUSH
Newer
Convert Video Formats Using FFMPEG