header是否可以改变HTML文件种类 比如404 400 200

qqsweb 2010-05-23 02:11:07
(Status-Line) HTTP/1.1 404 Not Found
这个是文件不存在header给IE的信息
我试着在404.php中加入
header ('(Status-Line): HTTP/1.1 200');
输出信息
(Status-Line) HTTP/1.1 404 Not Found
(Status-Line) HTTP/1.1 200
Connection Keep-Alive
Content-Type text/html
Date Sat, 22 May 2010 18:08:28 GMT
Keep-Alive timeout=15, max=100
Server Apache/2.0.63 (Win32) PHP/5.2.10
Transfer-Encoding chunked
X-Powered-By PHP/5.2.10

我希望404页面反馈给IE的信息是HTTP/1.1 200而不是HTTP/1.1 404 Not Found
这里头虽然有了200但IE只识别第一个提供的信息404文件不存在
改怎么做 是否可以改变?
...全文
126 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Dleno 2010-05-23
  • 打赏
  • 举报
回复

static function sendHeader($num,$rtarr=NULL){
$sapi = php_sapi_name();
$header_a = array(
'200' => 'OK',
'206' => 'Partial Content',
'304' => 'Not Modified',
'404' => '404 Not Found',
'416' => 'Requested Range Not Satisfiable',
);
if ($header_a[$num]) {
if ($sapi=='cgi' || $sapi=='cgi-fcgi') {
$headermsg = "Status: $num ".$header_a[$num];
} else {
$headermsg = "HTTP/1.1: $num ".$header_a[$num];
}
if (empty($rtarr)) {
header($headermsg);
} else {
return $headermsg;
}
}
return '';
}
qqsweb 2010-05-23
  • 打赏
  • 举报
回复
在404.php中加入

header ('HTTP/1.1 200');

我在我的windows搭建的
Apache/2.0.63 (Win32) PHP/5.2.10
环境下可以正常
但在其他环境下都是依然显示404错误
Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635

但是使用301

header ('HTTP/1.1 301');
却可以下面是GOOGlE成功抓取到的HTTP头信息
HTTP/1.1 301 Moved Permanently
Date: Sun, 23 May 2010 01:10:41 GMT
Server: Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
X-Powered-By: PHP/5.2.11
Content-Length: 14087
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧