网络编程 
首页 > 网络编程 > 浏览文章

ThinkPHP访问不存在的模块跳转到404页面的方法

(编辑:jimmy 日期: 2024/10/14 浏览:3 次 )

首先在ACTION中新建一个文件EmptyAction.class.php,其代码如下:

<"HTTP/1.0 404 Not Found");//使HTTP返回404状态码 
  $this->display("Public:404"); 
 } 
 } 
 "htmlcode">
<configuration>
 <system.web>
 <customErrors mode=”On” defaultRedirect=”error.asp”>
 <error statusCode=”404″ redirect=”notfound.asp” />
 </customErrors>
 </system.web>
 </configuration>

注:上文例中“error.asp”为系统默认的404页面,“notfound.asp”为自定义的404页面,使用时请修改相应文件名。
然后,在自定义的404页面“notfound.asp”中加入:

<%
 Response.Status = “404 Not Found”
 %>
 

php的404页面:

 if(//如果没有任何结果)
   {
   //以前是仅仅显示“该帖子已经不存在”的提示,现在是:
   require('/404.php');
   @header('HTTP/1.1 404 Not Found'');
   @header('Status: 404 Not Found');
   exit;
   }
 
上一篇:ThinkPHP3.1.3版本新特性概述
下一篇:解密ThinkPHP3.1.2版本之模块和操作映射