3

I'm looking for ways to know if an apache server receives a request , from another country (e.g germany) considering its a fair request (no spam , or proxies). I want it either to appear this as a separate entry(using dns request) in apache logs? or some kind of alert . Can this be possible.

1 Answer 1

1

You can have Apache2 detect where the user is coming from and adjust the variables in the header so yes you can log it, and setup a cron job to phrase the logs but you need access to a GEO IP database. Not all domains, hosts resolve as .de and even if its .de doesn't mean they are German based.

mod_geoip2 Apache module

This little module allows you to detect visitors using a GEOIP database and then redirect, block, log, and many other variables within the htaccess or header request.

For example

GeoIPEnable On GeoIPDBFile /path/to/GeoIP.dat

# Redirect one country RewriteEngine on RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$     RewriteRule ^(.*)$
http://www.domainname.com$1 [R,L]

# Redirect multiple countries to a single page RewriteEngine on RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(CA|US|MX)$ RewriteRule ^(.*)$
http://www.domainname.net/DE$1 [R,L]

The eaiest solution would to redirect them to a DE part of the site making the phrasing easier. You just duplicate the page and use noindex so that doesn't effect your rankings.

Check out mod_geoip2

GEO IP Databases Cost Money

IP addresses are ever expanding and changing from one country to another, in order to keep your database up to date you need to pay for this per X amount of requests. I recommend Maxmind for using their API as allows lot of freedom and pricing isn't to bad.

Simple Solution

Sorry there is no simple solution to do this, you could by all means resolve the host but many ISP's in Germany don't use just .de they use .net .com and so on! so your need a database to know what is what.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.