核心代码:
在php程序中,我们也经常需要考虑如何用php实现页面404跳转的写法,下面作者将如何用php进行404转向的写法和大家分享一下!
复制代码 代码如下:
代码如下
男篮世界杯赔率,@header("http/1.1 404 not found");
@header("status: 404 not found");
echo 'echo 404';
exit();
// 直接输出页面错误信息
@header("http/1.1 404 not found");
@header("status: 404 not found");
echo 'echo 404';
exit();
如果需要加载404页面可以如下代码,主要是注意文件路径
或者:
复制代码 代码如下:
代码如下
@header("http/1.1 404 not found");
@header("status: 404 not found");
include("../../404.htm");
exit();
// 跳转到错误页面,推荐使用这种方法
//
注意include文件的路径不能是http网络路径
@header("http/1.1 404 not found");
@header("status: 404 not found");
include("/404.html");
exit();
查看404是否设置成功可以利用firefox 的firebug插件来查看
我们也可以直接在 apache 设置 404
错误页面,具体定义方法如下:
在网站的根目录下新建一个 .htaccess
文件,然后在该文件中加入如下内容即可:
本文由美洲杯赔率发布于计算机教程,转载请注明出处:php 定义404页面的实现代码