Archive for April, 2009

IP based redirect for bots using .htaccess

Like all of us – I think – I really hate comment spammers. I really hate unruly bots, actually. I really do. If you start keeping stats of visitors on your site, you’ll quickly spot bots crawling all over your site, searching for all sorts of ways to epxloit your website. They look for email addresses, they try to submit spam comments, they try to find ways to enter your database, they do everything but help you. They are leeches. They stink. I really don’t like them…

Luckily, there are different ways to handle bots as well. If you’re using a .htacces file, for example, you can add a snippet to block the vermin based on their IP address. An idea I liked even better is to redirect the bots to a site that tries to reeducate the bots. You never know.

In stead of redirecting the bots to a governement site where they can take a seat and follow a hands-on course on cyber crimes, another good idea is to send the little bastards to a spam trap page. Gives me visions of all bots in the world swimming around in a pool of interlinked spam pages, never able to get out by them selves. Heaven…

So that’s what I do now, I redirect the bots to a spam trap. Typing in the IP’s in the required format for the .htaccess file, however, can be a PITA. Therefore, I wrote a little script to generate the .htaccess snippet based on a list of IP’s in their normal format. The .htaccess format itself comes from Am I Famous Now. Insert the URL where you want to send the bots to or leave the one I use, insert the IP’s of the bots and push the button:



The URL to refer the bots to:

The IP’s to refer (one per line):

Copy paste the snippet into your .htaccess file, and you’re all set. (WATCH OUT: if you don’t know what you’re doing, messing with .htaccess can wreck your site in a second. Don’t blame me. I told you.) This works fine, ofcourse, when you can easily keep track of the bots. When you have huge traffic on your site, you probably have a huge number of bots visiting it as well. In that case, you’re probably better of with a lean and mean, fully automated and integrated bot trapping/blocking device like this or this

Pentax K20D firmware update under Linux

Pentax has recently issued a new firmware update (1.03) for their current top DSLR, the K20D. Linux users might be suprised to see that only Windows and Mac users are supposed to download the firmware, as there’s only a download link for those two. A closer look to the accompanying text, however, shows that the Mac download is actually an ordinary zip file. I have yet to see a Linux distro that doesn’t support extraction of zip-files, and this particular zip-file extracts to the bin-file you need to update the camera. Even under Linux (or BSD or…)

Drupal: Combining Taxonomy Menu and Taxonomy Redirect

Taxonomy Menu is a very nice Drupal module that lets you create a menu based on a content type’s taxonomy. The taxonomy terms form the menu structure, and the way the nodes are displayed when a menu item (= taxonomy term) is selected can be customised using a custom view. I really like it. I like it so much, that I wanted the taxonomy terms displayed in the header of my nodes to link to the same menu structure, so that clicking on them was the same as clicking on the same term in the Taxonomy Menu.

Here enters Taxonomy Redirect. This module allows one to rewrite the url that the Taxonomy module creates. So instead of blabla.com/taxonomy/term/999 you can make the link blablabla.com/goto/this/instead/999. For this, you can define a redirect as plain text, or with a php snippet. Due to the link structure Taxonomy Menu uses, I had to resort to php for dynamically creating the Redirect link. The standard format for the link structure for Taxonomy Menu is “sitename.com/category/vid/pid1/pid2/tid” (with vid the vocabulary id, pid a parent term id, and tid the term id). The term “category” can be set in the settings for Taxonomy Menuy. Using plain text to define the Redirect link would f*** things up when the taxonomy term did not have any parents. Php worked fine, once I found out that the Redirect module defines a variable $tid for the term id, that you can use in your script. The code I used:

<?php
$output = “category/1/”;
$parents = taxonomy_get_parents_all($tid);
$parents = array_reverse($parents);
// Remove the child term from the array
array_pop($parents);
foreach ($parents as $parent) {
$output .= “$parent->tid”;
$output .= “/”;
}
$output .= $tid;
return $output;
?>

The “1″ behind “category” in the first line is for the vocabulary, so you’ll have to check what value you need there. Note that using php might not work straight away for anonymous users. To resolve this, have a look here