Skip to content

Cyber Sale: Save big on Moz Pro! Sign up by Dec. 6, 2024

Advanced seo 74da3a3

Blocking Bots Based on User-Agent

Ken Wisnefski

This YouMoz entry was submitted by one of our community members. The author’s views are entirely their own (excluding an unlikely case of hypnosis) and may not reflect the views of Moz.

Table of Contents

Ken Wisnefski

Blocking Bots Based on User-Agent

This YouMoz entry was submitted by one of our community members. The author’s views are entirely their own (excluding an unlikely case of hypnosis) and may not reflect the views of Moz.

Normally as SEOs our focus is on giving Google and other search engines as much access to the sites we are working on as possible. There are times however in which privacy is a good thing. We have found blocking bots based on the user-agent very useful for development servers where you might be hosting multiple sites which you do not want crawled or indexed.

With major SE emphasis on real time content and freshness it is imperative to be certain in our live pages and their elements within. Blocking bots access has certainly saved us the embarrassment and any potential problems with indexation of content in advance of intended release.

Below are examples in accomplishing this on either Apache or IIS.

APACHE

On Apache servers it is very easy to block unwanted bots using the .htaccess file. Simply add the following code to the file to block the engines.

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} Googlebot [OR]
RewriteCond %{HTTP_USER_AGENT} AdsBot-Google [OR]
RewriteCond %{HTTP_USER_AGENT} msnbot [OR]
RewriteCond %{HTTP_USER_AGENT} AltaVista [OR]
RewriteCond %{HTTP_USER_AGENT} Slurp
RewriteRule . - [F,L]

The following code will return a 403 error to Google

If you would prefer to redirect the bots to a specific page then just replace the last line above with the following.

RewriteRule ^.*$ "http\:\/\/www.yoursite\.com\/nobots.html" [R=301,L]

 

IIS

It is possible to do the same type of filtering on an IIS 7 server but it is more complicated. The easiest way I have found involves first installing the IIS URL Rewrite Module.

BOTS IIS

BOTS IIS2After the module is installed open the IIS Server Manager, select the site you would like to block, and open URL Rewrite.

Go to 'Add Rule(s)…' in the upper left of the window.

Select 'Request blocking' and click OK

 

 

 

 

IIS3

Use the following settings:

  • Block access based on: User-agent Header
  • Block request that: Matches the Pattern
  • Pattern (User-agent Header): Googlebot|Ads-Google|msnbot|Altavista|Slurp
  • Using: Regular Expressions
  • How to block: Send an HTTP 403 (Forbidden) Response

Then click 'OK'

 

IIS4

You can test your settings using Chris Pederick's great tool User Agent Switcher. When you first install it the options are a bit limited but a very exhaustive list of user agents can be found here. Using these methods to block user agents, while somewhat technical, will you or your developer the flexibility to work on-site without fear of indexation of pages that are in progress

Back to Top
Ken Wisnefski
WebiMax is a recognized leader in SEO (Search Engine Optimization) within the online marketing field. Our vast experience in assisting our clients gain substantial online visibility through our efforts has set us apart from the competition. Our "no-nonsense" approach has been developed through our 10+ years of hands on online marketing experience. We focus our efforts on truly partnering with our clients to provide them with the strategic partner they require to receive the optimal success from their online marketing. WebiMax manages online marketing campaigns for clients within SEO, PPC, SEM, Social Media and Reputation Management. WebiMax is also a leading web design agency. Specialties Online Marketing, Search Engine Optimization (SEO), Pay Per Click Management (PPC), Search Engine Marketing (SEM) Advertising, Display Ad Campaigns, Social Media Marketing, Online Reputation Management, Content Marketing, Inbound Marketing, Blogging, Web Design, Conversion Optimization, Consulting

Make smarter decisions with Moz API

Start building and scale easily with affordable plans

Read Next

Accelerate Your SEO Knowledge: New Webinar From Moz

Accelerate Your SEO Knowledge: New Webinar From Moz

Nov 11, 2024
How I Found Internal Linking Opportunities With Vector Embeddings

How I Found Internal Linking Opportunities With Vector Embeddings

Oct 03, 2024
Build a Search Intent Dashboard to Unlock Better Opportunities

Build a Search Intent Dashboard to Unlock Better Opportunities

Aug 29, 2024

Comments

Please keep your comments TAGFEE by following the community etiquette

Comments are closed. Got a burning question? Head to our Q&A section to start a new conversation.