仅当用户请求域的根并且来自特定国家/地区时才使用 mod_rewrite 和 mod_geoip 进行重定向

发布于 2024-08-24 10:04:49 字数 530 浏览 1 评论 0原文

我需要一个规则和条件来处理这种情况:

来自美国的用户访问www.domain.com、domain.com、www.domain.com/或domain.com/,这应该被重定向到www.domain.com/usvisitor/

但是,如果来自美国的用户访问 www.domain.com/anydirectory,它将让他们直接通过,而不会发生重定向。

例如。

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 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

記柔刀 2024-08-31 10:04:49

只是为了记录一下,解决了这个问题:

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]

真的很简单 - 哦!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文