簡體   English   中英

帶標題(位置)的開關箱中的重定向循環

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM