我們來介紹一下關于ThinkPHP訪問不存在的模塊跳到404頁面,有需要的朋友可參考參考,在ACTION中新建一個文件EmptyAction.class.php,文件中的代碼如下:
- <?php
- class EmptyAction extends Action{
- //開源代碼Vevb.com
- function _empty(){
- header("HTTP/1.0 404 Not Found");//使HTTP返回404狀態碼
- $this->display("Public:404");
- }
- }
- ?>
在apache中設置,在你的網站配置中加入 ErrorDocument 404 /404.html 即可.
在iis中設置,IIS/ASP.net下設置404錯誤頁面,打開apache httpd.conf配置文件或者新建.htaccess配置文件.
首先,修改應用程序根目錄的設置,打開 “web.config” 文件編輯,在其中加入如下代碼:
- <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;
- }
新聞熱點
疑難解答
圖片精選