题
这个问题已经有一个答案在这里:
由于某些原因一呼吁header()导致一个内部服务器错误我。我使用的PHP5和使用mod_rewrite广泛地在这个脚本(如果有帮助).这里是代码(排序):
<?php
include 'core/initialize.php'; // Loads the core class (and session manager class)
if($_GET['reset'] == 'true')
{
$core->Session->Visits = 0;
header('Location', 'index.html');
# header('X-Test', 'wtf'); // causes the error too :(
}
if(isset($core->Session->Visits)) $core->Session->Vists += 1;
else $core->Session->Visits = 0;
echo "Previous Visits: {$core->Session->Visits} (<a href='index.html?reset=true'>Reset</a>)";
?>
我的。就文件看起来是这样的:
# Start up the rewrite engine
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ navigator.php?nav=$1&%{QUERY_STRING} [NC]
解决方案
你用的是这个:
header('Location', 'index.html');
这不是办法 header
必须使用:第二个参数应该是一个布尔。
和第一一个应该是头部的名称+值。
所以,在你的情况下,事情是这样的:
header('Location: index.html');
只有一个参数;和名称的+':'+值 :-)
有一个例在文件:
第二种情况是特殊的 "Location:"header.它不仅不会 发送这个头回浏览器 但它也返回a REDIRECT(302) 状态码的浏览器,除非一些 3xx status code已经设定。
<?php
header("Location: http://www.example.com/"); /* Redirect browser */
/* Make sure that code below does not get executed when we redirect. */
exit;
?>
作为一个旁注,如果我没有记错的话,你应该使用全绝对URL当使用 Location
头;我知道使用相对URL工作(几乎?) 所有的浏览器,但它不是有效的,阅读时HTTP RFC,如果我记忆正确的。
作为第二旁注 (是的,答案已经被接受,但是也许这会是有用的,无论如何,对于下一次:-)) :该"内部服务器错误"可能表示你的PHP script遇到的一些样的错误。
在这种情况下,应检查 error_log
's文件...
...或者激活 error_reporting
和 display_errors
促进事情--至少在你的发展机。
不隶属于 StackOverflow