ThinkPHP访问不存在的模块跳转到404页面的方法
首先在ACTION中新建一个文件EmptyAction.class.php,其代码如下:
<?php
classEmptyActionextendsAction{
function_empty(){
header("HTTP/1.0404NotFound");//使HTTP返回404状态码
$this->display("Public:404");
}
}
?>
使用apache服务器的情况下需在apache中的网站配置中加入ErrorDocument404/404.html即可。
使用iis服务器的情况下需在iis中的IIS/ASP.net下设置404错误页面。
打开apachehttpd.conf配置文件或者新建.htaccess配置文件
首先,修改应用程序根目录的设置,打开“web.config”文件编辑,在其中加入如下内容:
<configuration> <system.web> <customErrorsmode=”On”defaultRedirect=”error.asp”> <errorstatusCode=”404″redirect=”notfound.asp”/> </customErrors> </system.web> </configuration>
注:上文例中“error.asp”为系统默认的404页面,“notfound.asp”为自定义的404页面,使用时请修改相应文件名。
然后,在自定义的404页面“notfound.asp”中加入:
<% Response.Status=“404NotFound” %>
php的404页面:
if(//如果没有任何结果)
{
//以前是仅仅显示“该帖子已经不存在”的提示,现在是:
require('/404.php');
@header('HTTP/1.1404NotFound'');
@header('Status:404NotFound');
exit;
}
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下