php网站404错误页面的写法

WBOY
Release: 2016-06-20 13:04:06
Original
1100 people have browsed it

每个网站基本上都不会少404这个页面,404页面的作用是在用户访问你网站中某个不存在的页面或者无法访问的页面的时候,这个时候通过404页面给当前用户一个友好明确的答复。告诉他这个地址是不存在的,并告诉他接来下该怎么办。

在php程序中,我们也经常需要考虑如何用php实现页面404跳转的写法,下面作者将如何用php进行404转向的写法和大家分享一下!

<p>@header("http/1.1 404 not found");</p>@header("status: 404 not found");<br />echo 'echo 404';//直接输出页面错误信息<br />exit();或者:@header("http/1.1 404 not found");<br />@header("status: 404 not found");<br />include("http://www.scutephp.com/404.html");<br />//跳转到某一个页面,推荐使用这种方法,注意include文件的路径不能是网络路径<br /><p>exit();</p>
Copy after login

查看404是否设置成功可以利用 firefox 的 firebug 插件来查看,具体查看方法如下:在已经安装firebug的情况下,用firefox浏览器打开要检查404状态码的页面,点击右下角小虫的图标,启动"网络"标签,依次打开"网络–所有/html–headers";如果一切正常,你就可以看到包括headers、响应在内的各项页面参数了。

另外这里也说下关于 apache 404 错误页面的定义,具体定义方法如下:


在网站的根目录下新建一个 .htaccess 文件,然后在该文件中加入如下内容即可:

ErrorDocument 404 http://www.scutephp.com/404.html
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!