与mod_rewrite的和mod_geoip重定向只有当用户请求域的根,是来自某一特定国家 [英] Redirecting with mod_rewrite and mod_geoip only if user asks for the root of the domain and are from a particular country
问题描述
我需要一个规则和条件来处理这种情况:
I need a rule and condition to handle this scenario:
用户来自美国的访问www.domain.com,domain.com,www.domain.com/或domain.com/~~V这应该被重定向到www.domain.com/usvisitor /
User from US visits www.domain.com, domain.com, www.domain.com/ or domain.com/ this should be redirected to www.domain.com/usvisitor/
但是,如果从美国访问用户www.domain.com/anydirectory~~V这将让他们直接通过没有重定向发生。
However, if a user from the US visits www.domain.com/anydirectory it will let them straight through without a redirection occurring.
如:
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]
我知道RewriteConditons和规则是错误的 - 只是不能让我的头周围
I know the RewriteConditons and rules are wrong - just can't get my head around it!
推荐答案
只是为了记录了它解决了:
Just for the record got it solved:
RewriteEngine On
GeoIPEnable On
GeoIPDBFile /var/share/GeoIP/GeoIP.dat
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$
RewriteRule ^$ http://www.domain.com/usvisitor/$1 [L,NC,QSA]
实在简单 - 卫生署
Simple really - doh!
这篇关于与mod_rewrite的和mod_geoip重定向只有当用户请求域的根,是来自某一特定国家的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!