直接用php的header发送404错误页面的方法实例
在php程序中,我们也经常需要考虑如何用php实现页面404跳转的写法,下面作者将如何用php进行404转向的写法和大家分享一下!
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy3753')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy3753>// 直接输出页面错误信息@header("http/1.1 404 not found");
@header("status: 404 not found");
echo 'echo 404';
exit();
或者:
// 注意include文件的路径不能是http网络路径
@header("http/1.1 404 not found");
@header("status: 404 not found");
include("/404.html");
exit();
我们也可以直接在 apache 设置 404 错误页面,具体定义方法如下:
在网站的根目录下新建一个 .htaccess 文件,然后在该文件中加入如下内容即可:
查看404是否设置成功可以利用 firefox 的 firebug 插件来查看,具体查看方法如下:
在已经安装firebug的情况下,用firefox浏览器打开要检查404状态码的页面,点击右下角小虫的图标,启动"网络"标签,依次打开"网络–所有/html–headers";如果一切正常,你就可以看到包括headers、响应在内的各项页面参数了。
您可能感兴趣的文章:
直接用php的header发送404错误页面的方法实例
php header 404跳转错误页面实例
php中header函数的用法举例详解
404 Not Found代码是什么意思 404错误是什么意思
php header是什么意思
PHP header()函数(301、404等错误设置)的用法
php header 使用详解
php header函数用法详解举例(2)
PHP header函数用法举例
php header()函数的简单例子