Is this a correct URI for the header('Locat开发者_运维知识库ion: ')
, specifically ./
?
header ('HTTP/1.1 301 Moved Permanently');
header ('Location: ./');
Thank you.
You can also use:
header('Location: /', false, 301);
I assume you want to redirect to the 'homepage', that'd be / instead of ./
You must use an absolute URI according to the spec so something like the following should work for you:
// 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();
精彩评论