Forum Moderators: phranque

Message Too Old, No Replies

Condional htaccess redirect using geo targeting

how to do Condional htaccess redirect using geo targeting

         

seperia

10:41 am on Mar 10, 2007 (gmt 0)

10+ Year Member



Hi Guys,

I have tried various things with no success and this is what I am after if anyone can help...

I want to redirect traffic from the US clicking on a certain link to one site and all other traffic to another.

I installed the geoIP module and it is working although i am not sure on how to make the conditional statement to implement the:

If (from US) then
go to US_out_URL_1
Else
go to Non-US_out_URL_2

This is what i got setup, which is not working :(

GeoIPEnable On
GeoIPDBFile /GeoIP.dat

RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$ [NC]
RewriteRule ^mydomain_URL$ [US_out_URL_1...] [R,L]

Redirect permanent [mydomain_URL...] [Non-US_out_URL_2...]

makes sense that it would not work but I am not sure on how to go about it...

any creative ides?

Thanks for the help,
David

jdMorgan

2:37 pm on Mar 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You cannot mix mod_alias and mod_rewrite directives if you wish to control execution order. On most servers, the Redirect directive of your "Else" clause will be executed before your RewriteRule, because mod_alias will be invoked first.

In order to get predictable results, stick to using mod_rewrite for the whole routine.

Jim

seperia

3:03 pm on Mar 10, 2007 (gmt 0)

10+ Year Member




Thanks for the quick response, although i am not sure how to implement what you suggested...

Can you please give me an example if you can?

I am new to this advanced htaccess manipulation :)

Thanks

seperia

12:03 am on Mar 11, 2007 (gmt 0)

10+ Year Member



Now it is all working :)

I used your idea of rearranging, please let me know if you think there is a better way.

Here is what i did, which is working:

GeoIPEnable On
GeoIPDBFile /GeoIP.dat

RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$ [NC]
RewriteRule ^mydomain_URL$ [US_out_URL_1...] [R=301]

#redirect non-www to www url
RewriteEngine on
RewriteCond %{HTTP_HOST}!^www\.mydomain\.com
RewriteRule (.*) [mydomain.com...] [R=301,L]

Redirect permanent [mydomain_URL...] [Non-US_out_URL_2...]

Hope this info will help other people who have this problem.

Thanks,
David