繁体   English   中英

Apache 基于 GeoIP 的重写规则

[英]Apache Rewrite Rule based on GeoIP

目前,我正在尝试基于 GeoIP 重定向域。 我已经安装了 GeoIP 模块。 我有以下 domain.conf 文件。 问题是登录工作正常,就像我的示例一样。com 将是印度用户的默认设置,而 us.example.com 将是美国用户访问该站点时的域。 但目前得到

redirected you too many times. 

注意:域按预期重定向,但出现上述错误。 我使用了反向代理,因为我的应用程序在端口 8080 上的 docker 中运行。

如果有人能给出正确的 apache 重写规则,那就太好了。

<VirtualHost *:80>
      ServerName example.com
       ServerAlias example.com us.example.com
       ProxyRequests Off
      ProxyPreserveHost On
      ProxyPass / http://localhost:8080/
      ProxyPassReverse / http://localhost:8080/

      GeoIPEnable On
      GeoIPDBFile /usr/share/GeoIP/GeoIP.dat
      GeoIPScanProxyHeaders On


      RewriteEngine on
      RewriteCond "%{ENV:GEOIP_COUNTRY_CODE}" ^US$
      RewriteRule http://us.example.com$1


      LogFormat "%a %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined

      ErrorLog ${APACHE_LOG_DIR}/example.com-error_log
      CustomLog ${APACHE_LOG_DIR}/example.com-access_log common
</VirtualHost>

感谢提前

尝试:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^us\.example\.com$ [NC]
RewriteCond "%{ENV:GEOIP_COUNTRY_CODE}" ^US$
RewriteRule ^ http://us.example.com [R=302,L]

您需要重新启动 apache,并确保在尝试查看上述是否有效之前清除浏览器缓存。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM