Archive for the 'WordPress' Category

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

Free advertisement

Apparently, a four letter brand name can come in handy…

ikea

Google Adsense ad language

When I started using Google Adsense, my ads were set in the wrong language: in stead of displaying ads in English, Google sent me ads in French. Even more: in stead of calling the whole thing “Ads by Google“, it was called “Google Annonces“. And all this happened on a site with not a single non-English word. It took me some time to find out how to change this, even though in the end it was pretty trivial. That’s why I decided to list some items you’ll want to check when the language of your ads are not the language you expected.

Google is pretty good in keeping secrets,  so I expect there are not a lot of people outside Google that know its recipe for selecting the language of ads they send you. We do know, however, that it is based on a range of different factors, and changing only one might not yield the result you were hoping for.

  • First of all, there are the -very- obvious ones: your personal settings in your Adsense account. Even though this site is hosted on a server in Seattle and  fully written in English, it still received French advertising. I think this is due to the fact that that is the closest they could get to my mother country. Mind you, the language in my account was set to English. You can’t move to another country, in order to have your ads displayed in another country, of course (or if you do, you must have a great website, can I join?) but keep it in mind anyway.
  • Then we go to the – for the less web savvy users – less obvious ones: the meta information in your sites headers. Every webpage starts with a bit of information about itself. This information is formatted in tags, that are called the meta tags. One piece of information you can share with the world, is the language used on the page. I found that my WordPress header didn’t include this information by default. You can change this by adding it to your header.php file. You can find this file in the directory of the theme you’re using (e.g. wp-content->themes->default->header.php). You can open it with any text editor, and then you want to change the line that looks like this:
    <html xmlns=”http://www.w3.org/1999/xhtml” <?php language_attributes(); ?>>

    into this:

    <html xmlns=”http://www.w3.org/1999/xhtml” <?php language_attributes(); ?> xml:lang=”en” lang=”en” >

    Now you let the browsers of your visitors and Google or any other robot know that the language of your webpage is English (If you want another language, you’ll have to change the “en” of course). That’s what did it for me.

  • And now we go into the really obscure parts: the things you display on your page. It seems to make sense that Google looks at the words you use, and tries to link them to a certain language. So if your website is in Spanish, then it makes sense that the ads are in Spanish, right? But if that’s what they do, then that’s only a part of the story. Apparently, the  use of non-English characters can upset the Great Googly Moogly language detector as well. So if tweaking of all the above setting doesn’t help, you might want to check on what exactly you’re displaying.
  • There’s another factor influencing the language of the ads shown on your site, but there’s not much you can do about it yourself: the locality of the visitor. A visitor’s location is obviously a strong indication of his language. So if you’re located in a Spanish speaking region, and visit an English website, you can still receive adds in Spanish. If you want to check what people in another region will see, you might try to use some kind of a proxy service. (The last time I checked www.webproxy.pro for example, its IP address returned an address in the States.)
  • If after all these great tips, you’re still receiving ads in click language, then alas, I don’t know what to do. If you do have other tips, though, do not hesitate to put them in a comment!

Cheers