[英]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.