Redirecting only if user asks for the root of the domain nad are froma particular country

Posted by lphmedia on Stack Overflow See other posts from Stack Overflow or by lphmedia
Published on 2010-03-11T20:35:03Z Indexed on 2010/03/11 20:39 UTC
Read the original article Hit count: 166

Filed under:

Hi,

I need a rule and condition to handle this scenario:

User from US visits www.domain.com, domain.com, www.domain.com/ or domain.com/ this should be redirected to www.domain.com/usvisitor/

However, if a user from the US visits www.domain.com/anydirectory it will let them straight through without a redirection occurring.

eg.

RewriteEngine On  
RewriteBase /

GeoIPEnable On  
GeoIPDBFile /var/share/GeoIP/GeoIP.dat  

RewriteEngine on  
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$  
RewriteCond %{HTTP_HOST} ^domain.com$ [L]  
RewriteRule ^/$ http://www.domain.com/usvisitor$1 [L]  

I know the RewriteConditons and rules are wrong - just can't get my head around it!

© Stack Overflow or respective owner

Related posts about mod-rewrite