[英]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 -->";
?>
这是我的代码,重定向到相应的域路径。 我将DE大小写更改为/ en,因为我在德国,想测试重定向。 但是每次我使用DE ISO时,都会出现“多次重定向”超时。 如果我通过来自美国或亚洲的网络代理进行连接,也会发生这种情况。
有什么想法或建议吗?
将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.