简体   繁体   中英

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. But every time I hit with DE ISO I get a "to many redirects" timeout. 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/ :

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

?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM