首页 > 开发 > ThinkPHP > 正文

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

2020-10-12 21:03:09
字体:
来源:转载
供稿:网友

我们来介绍一下关于ThinkPHP访问不存在的模块跳到404页面,有需要的朋友可参考参考,在ACTION中新建一个文件EmptyAction.class.php,文件中的代码如下:

  1. <?php  
  2. class EmptyAction extends Action{  
  3. //开源代码Cuoxin.com 
  4.     function _empty(){  
  5.         header("HTTP/1.0 404 Not Found");//使HTTP返回404状态码  
  6.         $this->display("Public:404");  
  7.     }  
  8. }  
  9. ?> 

在apache中设置,在你的网站配置中加入 ErrorDocument 404 /404.html 即可.

在iis中设置,IIS/ASP.net下设置404错误页面,打开apache httpd.conf配置文件或者新建.htaccess配置文件.

首先,修改应用程序根目录的设置,打开 “web.config” 文件编辑,在其中加入如下代码:

  1. <configuration> 
  2. <system.web> 
  3. <customErrors mode=”On” defaultRedirect=”error.asp”> 
  4. <error statusCode=”404″ redirect=”notfound.asp” /> 
  5. </customErrors> 
  6. </system.web> 
  7. </configuration> 

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

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

php 404,代码如下:

  1. if(如果没有任何结果) 
  2.     { 
  3.     //以前是仅仅显示“该帖子已经不存在”的提示,现在是: 
  4.     require(’/404.php’); 
  5.     @header(’HTTP/1.1 404 Not Found’); 
  6.     @header(’Status: 404 Not Found’); 
  7.     exit
  8.     } 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选