Geotargeting Wordpress plugins

kyaizen

揸緊中指
May 26, 2007
606
1
0
My Wistia bill shot up to $300 and I figured that I had to redirect freeloaders (India, Nigeria, Pakistan, Kenya, Philippines) elsewhere to save bandwidth.

Am considering a plugin like WP Traffic Tools to geo-redirect. Anyone have experience with this?

Plugins like Wordfence also do geotargeting.

Anything else that anyone has tried, used and liked?


DISCLAIMER: I have no financial interest in WP Traffic Tools and Wordfence, and do not know the people behind those products.
 


You can do this at Apache level using the mod_geoip2 Apache module and then either blocking everyone else and whitelisting certain countries or allowing everyone else and blacklisting certain countries.

You can also use the Maxming GeoIP class files and do this at PHP level.

Tell me the kind of solution you're looking at and I'll be able to help you better.


My Wistia bill shot up to $300 and I figured that I had to redirect freeloaders (India, Nigeria, Pakistan, Kenya, Philippines) elsewhere to save bandwidth.

That hurt a bit mang :(
 
Maxmind* :)

Also Incapsula has country level blocking if you want to do that.

I've read (correct me if I am wrong) that large scale blocking via IPtables, htaccess can be reasouce intensive, so Incapsula might be a good alternative if you do not have server resources to spare.

Personally I would go with Bloghue's php/Maxmind approach.
 
You can do this at Apache level using the mod_geoip2 Apache module and then either blocking everyone else and whitelisting certain countries or allowing everyone else and blacklisting certain countries.

You can also use the Maxming GeoIP class files and do this at PHP level.

Tell me the kind of solution you're looking at and I'll be able to help you better.

Pretty simple requirement.

In pseudo code -

If country == (list of unwanted countries) then redirect(URL);
Else do nothing
 
PHP, ideally. Are there pros and cons regarding each option?
 
Alright, server level it is then. How? Me not too much of an Apache hacker, really.
 
My Wistia bill shot up to $300 and I figured that I had to redirect freeloaders (India, Nigeria, Pakistan, Kenya, Philippines) elsewhere to save bandwidth.

Am considering a plugin like WP Traffic Tools to geo-redirect. Anyone have experience with this?

Plugins like Wordfence also do geotargeting.

Anything else that anyone has tried, used and liked?


DISCLAIMER: I have no financial interest in WP Traffic Tools and Wordfence, and do not know the people behind those products.

WordPress GeoTargeting Plugin :: TheWordPress.net

$25 and one of the best I've found. Works well on my geotargeted sites for country level redirects/changing content, etc..
 
Alright, server level it is then. How? Me not too much of an Apache hacker, really.

Running it at PHP level will require a query towards two load files that will have to be downloaded and uploaded to your server. Also, core wordpress files (primarily index.php) will have to be edited. But that or the JS variant are the only option if you're on a shared hosting.

As far as server level here we go then, I am assuming you're on a VPS or a dedicated? If so ask your host to install, MaxMind APIs: mod_geoip2 Apache module on your server.

Once it has been installed and activated, simply add the following to your site's .htaccess (Remember to get the file location for GeoIP.dat from your host)

GeoIPEnable On
GeoIPDBFile /path/to/GeoIP.dat

SetEnvIf GEOIP_COUNTRY_CODE IN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PK BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE KE BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE PH BlockCountry
# ... You can add more countries here

Deny from env=BlockCountry
The above code will block India, Nigeria, Pakistan, Kenya and Philippines.

============

There is also a javascript based redirect version around.

You can see it here [JavaScript] Javascript Redirect Script - BH From WF - Pastebin.com

However, remember though - it will have a slight slag in load time while the query to maxmind is done, the data parsed and the http header sent. So if you aren't concerned with load times, you can use that one as well.

Let us know how it goes.
 
If you use cloudflare you could use $_SERVER["HTTP_CF_IPCOUNTRY"], it works
 
Thanks, BlogHue. That was awesome.

What if I want to redirect instead of block?
 
Thanks, BlogHue. That was awesome.

What if I want to redirect instead of block?

More details and samples are available on maxminds page

MaxMind APIs: mod_geoip2 Apache module

In order to do a redirect, you use something like this

GeoIPEnable On
GeoIPDBFile /path/to/GeoIP.dat

# This code will redirect US visitors to the domain mentioned
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$
RewriteRule ^(.*)$ http://www.america.com$1 [R,L]

# This will redirects visitors from India, China and Philippines to google.com
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(IN|CH|PH)$
RewriteRule ^(.*)$ http://www.google.com$1 [R,L]

Oh! And a full list of country codes can be found here - http://en.wikipedia.org/wiki/ISO_3166-1
 
With the MM apache setup you can also yank that variable into PHP too.

This way you can control it at the entire site level for some sites, and within php for other usages on other sites.
 
WPTT will not work well with caching as it is now. Wordfence is one of the best plugins I've ran into to date and even if you don't use it for your geo-routing solutions it's awesome for malware protection, recovery, monitoring, and spider throttling too. For the geo-country blocking it's 17.95/ year per site though.

I can't believe more people are not familiar with WP Traffic Tools though! It's an incredible affiliate marketing tool.