[英]Redirect Loops in Switch Case with header(location)
<?php
$rexgeoip = new RexGeoIp;
$iso = strtoupper( $rexgeoip->getCountryIso() );
switch ($iso) {
case 'DE':
header("Location: http://www.domain.de/en/",TRUE,301);
break;
case 'AT':
header("Location: http://www.domain.de",TRUE,301);
break;
case 'CH':
header("Location: http://www.domain.de",TRUE,301);
break;
default:
header("Location: http://www.domain.de/en/",TRUE,301);
break;
}
}
echo "<!-- your iso is $iso -->";
?>
This is my code which redirects to the corresponding domain path. 这是我的代码,重定向到相应的域路径。 I changed the DE case to /en because I'm in Germany and want to test the redirect.
我将DE大小写更改为/ en,因为我在德国,想测试重定向。 But every time I hit with DE ISO I get a "to many redirects" timeout.
但是每次我使用DE ISO时,都会出现“多次重定向”超时。 This also happens if I connect via a web-proxy from US or Asia.
如果我通过来自美国或亚洲的网络代理进行连接,也会发生这种情况。
Any ideas or suggestions? 有什么想法或建议吗?
Add de
to the path and don't redirect in the script which is responsible for http://www.domain.de/de/
or for http://www.domain.de/en/
: 将
de
添加到路径中,并且不要在负责http://www.domain.de/de/
或http://www.domain.de/en/
的脚本中重定向:
<?php
$rexgeoip = new RexGeoIp;
$iso = strtoupper( $rexgeoip->getCountryIso() );
switch ($iso) {
case 'DE':
header("Location: http://www.domain.de/en/",TRUE,301);
exit;
break;
case 'AT':
header("Location: http://www.domain.de/de/",TRUE,301);
exit;
break;
case 'CH':
header("Location: http://www.domain.de/de/",TRUE,301);
exit;
break;
default:
header("Location: http://www.domain.de/en/",TRUE,301);
exit;
break;
}
}
echo "Script never gets here";
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.