Welcome to WebmasterWorld Guest from 54.159.26.69

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Using .htaccess to redirect by country

Based on ip2nation database

     

Bobby

4:09 pm on Dec 18, 2005 (gmt 0)

10+ Year Member



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?

jdMorgan

4:16 pm on Dec 18, 2005 (gmt 0)

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



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...]

Jim

Bobby

5:22 pm on Dec 18, 2005 (gmt 0)

10+ Year Member



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?

 

Featured Threads

Hot Threads This Week

Hot Threads This Month