【发布时间】:2011-04-22 06:34:05
【问题描述】:
我正在尝试使用 PHP 脚本重定向到基于 HTTP_HOST 或 SERVER_NAME 的特定路径。
我已经尝试过这些脚本:
1。
$domain = $_SERVER["SERVER_NAME"];
if (($domain == "example.dk") ||
($domain == "www.example.dk")) {
header("location: /index.php/da/forside");
}
?>
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();
}
?>
和其他类似的脚本。要么页面永远加载,要么浏览器返回一些重定向错误。
【问题讨论】:
-
您打开的初始网址是什么?
-
仅供参考,在您的第一个示例中,位置必须是完全限定的 URL,而不是相对路径。
-
@Nirmal 无论是相对 URL 还是绝对 URL,都存在同样的问题