首頁 繪圖設計 工作閒聊 比賽活動 美術討論 標籤 圖片
回上頁
[Web] Using Apache Error Document
Type(Type) 2009/1/6 01:27 (Since 2003/8/2 11:30)
Goal: Customized Web Error Message

Exp. Env: Vovo2000.Com ( Apache 2 + PHP )

Method:

1. 在 httpd.conf 建立
ErrorDocument 404 "/my/handle/path/myError.php?error=404"
當然,也可以用靜態網頁或純文字。(這裡好像 error code 不能用 RegEx?)

2. 寫一個 myError.php / perl (CGI) 去接
3. 寫好了,完成!(很簡單吧?~ )

另外, 2. 這個 PHP 如附件,可以 download
代碼:

<?PHP

     if (trim($HTTP_GET_VARS["error"]) != '')
   {
      $e = intval($HTTP_GET_VARS["error"]);
      $msg = "";
      $error_msg_2 = "<h1>".$e." ";
      $google404 = 0;
         
        switch ( $e )
      {
         case 403: $msg .=  'Forbidden';   break;
         case 404: $msg .= 'Not Found';   break;
         case 400: $msg .=  "Bad Request"; break;
         case 401: $msg .=  "Unauthorized"; break;
         case 402: $msg .=  "Payment Required"; break;
         case 405: $msg .=  "Method Not Allowed"; break;
         case 406: $msg .=  "Not Acceptable"; break;
         case 407: $msg .=  "Proxy Authentication Required"; break;
         case 408: $msg .=  "Request Timeout"; break;
         case 409: $msg .=  "Conflict"; break;
         case 410: $msg .=  "Gone"; break;
         case 411: $msg .=  "Length Required"; break;
         case 412: $msg .=  "Precondition Failed"; break;
         case 413: $msg .=  "Request Entity Too Large"; break;
         case 414: $msg .=  "Request-URI Too Long"; break;
         case 415: $msg .=  "Unsupported Media Type"; break;
         case 416: $msg .=  "Requested Range Not Satisfiable"; break;
         case 417: $msg .=  "Expectation Failed"; break;
         case 500: $msg .=  "Internal Server Error"; break;
         case 501: $msg .=  "Not Implemented"; break;
         case 502: $msg .=  "Bad Gateway"; break;
         case 503: $msg .=  "Service Unavailable"; break;
         case 504: $msg .=  "Gateway Timeout"; break;
         case 505: $msg .=  "HTTP Version Not Supported"; break;
         default:
            $msg .= "Error";
            break;
        }

        $msg1 = $msg;
      $msg .= "</h1>";
      $error_msg_2 .= $msg;
     }

   $part_main = '<head><title>{ERROR_MSG_1}</title></head><body bgcolor=#E4C70F>{ERROR_MSG_2}<a href=/>Vovo2000.Com</a><hr>';
   $part_main = str_replace( "{ERROR_MSG_1}", ($e." ".$msg1), $part_main );
   $part_main = str_replace( "{ERROR_MSG_2}", $error_msg_2, $part_main );
   $part_main .= '</body>';

   echo $part_main;
   
?>


參考文件:
[1] RFC 2616 HTTP 1.1, http://www.w3.org/Protocols/rfc2616/rfc2616.html

#apache
#errordocument
#404
#403

#apache by Type
#errordocument by Type
#404 by Type
#403 by Type
Type(Type) 2003/8/2 11:33
他的效果如附件的圖~

以「403」為測試。

Page Not Found.

ming(ming) 2004/7/22 17:02
剛好在找這個,太感謝了 😊 😊 😊
Type(Type) 2009/1/6 01:13

增強 404 網頁



Google Sitemap webmaster
提供了另外一個 404 增強處理,各位參考一下

代碼:

<script type="text/javascript">
  var GOOG_FIXURL_LANG = 'zh-TW';
  var GOOG_FIXURL_SITE = 'http://vovo2000.com/';
</script>
<script type="text/javascript"
    src="http://linkhelp.clients.google.com/tbproxy/lh/wm/fixurl.js"></script>

(16,743 views)
[更多討論] 討論區 Windows, Linux, Perl, PHP, C/C++, Driver, Web 理論、應用、硬體、軟體
回上頁

"[Web] Using Apache Error Document" 傳統頁面(電腦版)

首頁 繪圖設計 工作閒聊 比賽活動 美術討論 標籤 圖片
傳統桌面版 [ 登入/註冊 ]
© Vovo2000.com Mobile Version 小哈手機版 2024