【问题标题】:Redirect to subdomain gives redirect loop error重定向到子域会导致重定向循环错误
【发布时间】:2013-11-23 09:24:39
【问题描述】:

这是我的代码,放在我域主目录的 htaccess 中。试图将国家流量(使用 mod_geoip)重定向到我的子域。

GeoIPEnable On

RewriteEngine On 
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$ [NC]
RewriteRule ^(.*)$ http://sub.domain.com/$1 [R,L] 

但是,当我将其付诸实践时,我遇到了重定向循环错误。当我将重写规则切换到 domain.com 然后将文件放入 sub.domain.com 时,它似乎可以工作。我的代码有什么问题?谢谢!

【问题讨论】:

    标签: .htaccess loops redirect subdomain geoip


    【解决方案1】:

    感谢阿努巴瓦的帮助。我环顾四周,发现这个修改似乎可以解决问题。对RewriteRule 进行了更改。

    GeoIPEnable On
    
    RewriteEngine On 
    RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$ [NC]
    
    RewriteRule !^(subdomain) http://www.subdomain.domain.com [L,R]
    

    我把它放在我的 .htaccess 中,它起作用了!我也看到了使用子文件夹重定向的这种用法。

    【讨论】:

      【解决方案2】:

      在主机已经是sub.domain.com 时尝试使用此规则和附加条件来避免重定向:

      GeoIPEnable On
      
      RewriteEngine On 
      
      RewriteCond %{HTTP_HOST} !^sub\.domain\.com$ [NC]
      RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$ [NC]
      RewriteRule ^(.*)$ http://sub.domain.com/$1 [R,L] 
      

      【讨论】:

      • 附加条件似乎不起作用。它实际上似乎覆盖了其他条件和规则,只是将我发送到 domain.com。不过感谢您的建议!
      猜你喜欢
      • 2015-12-12
      • 1970-01-01
      • 2016-06-15
      • 2015-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-09
      相关资源
      最近更新 更多