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

Apache Web Server Forum

Using .htaccess to redirect by country
Based on ip2nation database

10+ Year Member

Msg#: 5148 posted 4:09 pm on Dec 18, 2005 (gmt 0)

I recently downloaded the ip2nation database of IP addresses and associated countries.

I can add a script in PHP to redirect or block access to a site based on country code supplied by the database, but there are a lot of pages in the site to apply the script to!

Is there an easier way to simply redirect a user based on country code by using .htaccess?



WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 5148 posted 4:16 pm on Dec 18, 2005 (gmt 0)

In .htaccess, there's no neat solution. In httpd.conf, you can use the RewriteMap directive to call a cgi script to do the lookup, and act based on the returned value. But RewriteMap is not available in the .htaccess context.

Perhaps your needs will be met by using PHP's "auto-prepend" function to automatically include the call to your lookup script on all of your php pages. See [webmasterworld.com...]



10+ Year Member

Msg#: 5148 posted 5:22 pm on Dec 18, 2005 (gmt 0)

Thanks for your input Jim.

I'm a fish out of water here, I know next to nothing about how servers work.

I had a look at the thread you suggested begun by mvl22, but I can't say I understand much.

As it is now I can simply call the script up with an "include" command in each of the (very many) files. If I understand correctly then there is a way to configure the server to automatically attach this script either before or after the rest of the files. In layman's terms, what do I need to do and where do I need to do it to avoid manually placing "include" on every file?

I asked the tech guy who takes care of the server to set it so it would parse .html files looking for php code (otherwise I'd have to rename the files and would thus compromise all the SEO work done).

Would using "auto-prepend" in this case work for the .html files as well?

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