使用标题(位置)重定向开关案例中的循环

时间:2013-05-21 14:10:44

标签: php redirect switch-statement

<?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时都会出现“到多次重定向”的超时。如果我通过美国或亚洲的网络代理连接,也会发生这种情况。

有任何想法或建议吗?

1 个答案:

答案 0 :(得分:0)

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";

?>