这是header('Location: ')
的正确URI,特别是./
吗?
header ('HTTP/1.1 301 Moved Permanently');
header ('Location: ./');
谢谢。
答案 0 :(得分:7)
您也可以使用:
header('Location: /', false, 301);
我假设你想要重定向到'主页',那就是/而不是./
答案 1 :(得分:6)
您必须使用absolute URI according to the spec,因此以下内容适用于您:
// check if the server is secure or not to determine URL prefix
if(isset($_SERVER['HTTPS']) and 'on' === $_SERVER['HTTPS']) {
$location = 'https://';
} else {
$location = 'http://';
}
// get the servers base URL
$location .= $_SERVER['SERVER_NAME'] . '/';
// grab the current URI without a file name in it
$location .= dirname($_SERVER['REQUEST_URI']) . '/';
header('Location: ' . $location);
exit();