Fra*_*isc 8 php location uri header
这是一个正确的URI header('Location: '),特别是./?
header ('HTTP/1.1 301 Moved Permanently');
header ('Location: ./');
Run Code Online (Sandbox Code Playgroud)
谢谢.
您还可以使用:
header('Location: /', false, 301);
Run Code Online (Sandbox Code Playgroud)
我假设你想重定向到'主页',那就是/而不是./
// 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();
Run Code Online (Sandbox Code Playgroud)