Shopping Cart Forum

Go Back   eShop Forums - eCommerce Help Forum for Shopping Cart Owners. > Tech Corner > PHP/HTML/CSS/JavaScript and Servers
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
PHP/HTML/CSS/JavaScript and Servers Pick up tips and exchange info on the technical side of having a web presence.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 30-10-2007, 04:25 AM
Lawrence Lawrence is offline
Forum Admin
 
Join Date: Aug 2007
Location: Kenley, Surrey, UK
Posts: 1,226
Thanks: 2
Thanked 82 Times in 82 Posts
Default How to use mod_rewrite to block bad bots with .htaccess

This method will only work on Apache servers with mod_rewrite installed. There are ways to do it on some other servers but Apache is by far the most commonly used webserver so I will use it for this example.
If you already have an .htaccess file in your web root then edit the code below to suit your requirements and append it to the end of the file. If you don't have an .htaccess file then create a text file in the root of your web server and name it .htaccess.

Edit the "BadBot" part of each line to match the nuisance bots. Each entry must end with [OR] with the exception of the last one on the list as shown below.

Code:
 
RewriteEngine On 
RewriteCond %{HTTP_USER_AGENT} ^BadBot_1 [OR] 
RewriteCond %{HTTP_USER_AGENT} ^BadBot_2 [OR] 
RewriteCond %{HTTP_USER_AGENT} ^BadBot_3 [OR] 
RewriteCond %{HTTP_USER_AGENT} ^BadBot_4 
RewriteRule ^.* - [F,L]
If you need to block an actual IP or domain rather than the agent then you can use {REMOTE_ADDR} instead of {HTTP_USER_AGENT} and replace the bot name with an IP or domain.

Another way to block IPs and domains that doesn't require the use of Mod_Rewrite is to use the method described in this post.
http://www.eshopforums.com/f30/how-u...ur-website-91/ though it won't work with agent names.
__________________
Lawrence
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use .htaccess to block IPs and domains from your website. Lawrence PHP/HTML/CSS/JavaScript and Servers 1 04-07-2008 10:40 PM
How to display your email address on a page so the spam bots cannot read it. Lawrence PHP/HTML/CSS/JavaScript and Servers 1 18-01-2008 01:57 PM
How to 301 redirect non-www URLs to www ones and vice versa using .htaccess Lawrence PHP/HTML/CSS/JavaScript and Servers 0 26-10-2007 02:21 PM
Can I block an IP with php? PeterC PHP/HTML/CSS/JavaScript and Servers 4 08-08-2007 04:55 PM

Google

Edible Graphics, Affordable E-Commerce, Web Shops & Custom Form Scripts
Fair Trade Quality Handmade Photo Albums & Gifts
tech news, product reviews, the latest home and business technology, the latest in digital imaging


Content Relevant URLs by vBSEO 3.0.0