PDA

View Full Version : .htaccess / geoIP: deny or forward per country


Marv
12-26-2013, 09:42 AM
Hi folks,
I hope you all had a fabulous christmas time by now! :)

I?ve run into a problem with my forums and the server. May be someone already has this one solved for his own forums - or knows a way, how to solve that.

My site is been overruned by requests from the asian ans russian region now for weeks and causes the server to run permanently on very high loads and it?s slowing down the server, that it?s a pain in the a*se to visit the site. I would like to forward those bots to a honeypot on one of my other servers, instead of blocking them. So they can be reported automaticly to spamhouse.org and others. At the same time - for human visitors - I?ld like to forward visitors to language/origin-matching specific sites on my website.

First: I can?t install a geoIP as apache module. I couldn?t figure out why - and I don?t want to do something nasty, that in the end is crashing the server - but I have a second best: I have PIWIK installed and with it a geoIP database as geoip_country.php file, running in a subdir. That works pretty fine for PIWIK.

But how could I make use of this geoip-file in connection with a .htaccess so, that the origin of visitors/bots are checked by the .htaccess/geoIP and become deflected to another http target? I?ve already heard this shouldn?t be a problem (more like a rumor while a chit-chat), but - to be honest - I have no clue what has to be done, to make this happen.

I?ld really appreciate, if someone could lend me a helping hand with that.
Anyone....?

ozzy47
12-26-2013, 10:51 AM
Try this neat tool, http://incredibill.me/htaccess-block-country-ips

I have read in some places though that doing this through .htaccess can slow the site down.

Or you can try by blocking the country code.
SetEnvIf CF-IPCountry CN BuzzOff=1
SetEnvIf CF-IPCountry RU BuzzOff=1
SetEnvIf CF-IPCountry IN BuzzOff=1
Order allow,deny
Allow from all
Deny from env=BuzzOff

In this example, notice "CN", "RU" and "IN" in the first three lines. These stand for China, Russia and India. Edit those to suit your needs (and add or remove as many lines as you like) by consulting the list of internet country abbreviations (http://www.asiteaboutnothing.net/c_country-codes.html).

Marv
12-26-2013, 12:26 PM
Thanks for the input, Ozzy :up:

While thinking about that I`d to notice, that redirecting visitors from i.e. country en-US to /en-US would redirect even the GoogleBots, which would have an impact to all the other sites regarding SEO and SERPs and would make BigG stop to crawl those sites. Beside that I?m really not quite sure, wether Google would call this cloaking or not..

In the end I guess I should try to redirect human visitors by the language informations in the head of the browser:

RewriteCond %{HTTP:Accept-language} en-US [NC]
RewriteRule ^$ /en-US [L,R=301]Hope that will do the trick for humans. And hopefully the bots don?t change to us-IP?s..

--------------- Added 1388072353 at 1388072353 ---------------


Or you can try by blocking the country code.
SetEnvIf CF-IPCountry CN BuzzOff=1
SetEnvIf CF-IPCountry RU BuzzOff=1
SetEnvIf CF-IPCountry IN BuzzOff=1
Order allow,deny
Allow from all
Deny from env=BuzzOffIn this example, notice "CN", "RU" and "IN" in the first three lines. These stand for China, Russia and India. Edit those to suit your needs (and add or remove as many lines as you like) by consulting the list of internet country abbreviations (http://www.asiteaboutnothing.net/c_country-codes.html).

Ozzy,
I?m now adding country after country into that..and somehow it feels like becoming a racist while excluding all those countries. Does it work even the other way like this? SetEnvIf CF-IPCountry DE BuzzOff=1
SetEnvIf CF-IPCountry UK BuzzOff=1
SetEnvIf CF-IPCountry US BuzzOff=1
Order allow,deny
Deny from all
Allow from env=BuzzOff

May sound dumb, but I?ve never heard about that BuzzOff before.. :o

ozzy47
12-27-2013, 10:24 AM
TBH I am not sure, I have never tried it that way, but in theory it should work.

But As I stated before, the more countries that are blocked, the more resources are needed by the server. I had a partner on our server before, and he blocked a boat load of countries with the CSF firewall, and I did notice a performance hit.