homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Redirect visitor by country using .htaccess
I want to dynamically redirect visitors from IPs in certain countries

5+ Year Member

Msg#: 3230624 posted 8:46 pm on Jan 24, 2007 (gmt 0)

I need to 301 redirect visitors to my dot ca website from countries A and B to my dot com website. (Please note that my dot ca website is deliberately not indexed by search engines - robots.txt blocks all bots).

I realize that I need to lookup each visitor's IP address to see what country they are from. I can do this using a few options from various software providers (ie: a local database lookup with a database that needs constant updating OR using a web service where the database is stored and updated by the softare provider). I'd prefer to use the web service option.

My question: Can either option be done from within my .htaccess file? This way, I can avoid having to edit every page on the site (100+) to add a snippet of PHP code to do the IP lookup and 301 accordingly.

I think what I'm asking is - can the contents of the .htaccess file be updated dynamically (since the IP addresses/ranges of the blocked countries are constantly changing)?




10+ Year Member

Msg#: 3230624 posted 12:25 am on Jan 27, 2007 (gmt 0)

I can't think of a way to do it by using external web services, but you can accomplish what you want with the maxmind mod_geoip apache extension. Google "maxmind mod_geoip". It is fantastic.

They have free and commercial versions of their database, but you will have to keep a local copy. Better that way anyway - you wouldn't want to be doing an external request for every page hit.


5+ Year Member

Msg#: 3230624 posted 4:29 pm on Jan 29, 2007 (gmt 0)

Thanks sabai! A perfect solution.

Too bad Maxmind's website is so difficult to navigate because if it wasn't I would've already found this myself :)

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved