我正在尝试使用PHP脚本重定向到基于HTTP_HOST或SERVER_NAME的特定路径.
我试过这些脚本:
1.
$domain = $_SERVER["SERVER_NAME"];
if (($domain == "example.dk") ||
($domain == "www.example.dk")) {
header("location: /index.php/da/forside");
}
?>
Run Code Online (Sandbox Code Playgroud)
2.
switch ($host) {
case 'example.dk':
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.dk/index.php/da/forside/");
exit();
case 'www.example.dk':
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.dk/index.php/da/forside/");
exit();
default:
header("Location: http://www.example.se");
exit();
}
?>
Run Code Online (Sandbox Code Playgroud)
和其他类似的脚本.页面永远加载或浏览器返回一些重定向错误.