站长百科 | 数字化技能提升教程 数字化时代生存宝典
首页
数字化百科
电子书
▼
建站程序
开发
服务器
办公软件
开发教程
▼
服务器教程
软件使用教程
运营教程
热门电子书
▼
CSS教程
WordPress教程
导航
程序频道
推广频道
网赚频道
人物频道
网站程序
网页制作
云计算
服务器
CMS
论坛
网店
虚拟主机
cPanel
网址导航
WIKI使用导航
WIKI首页
热点词条
最新资讯
网站程序
站长人物
页面分类
使用帮助
编辑测试
创建条目
网站地图
站长百科导航
站长百科
主机侦探
IDCtalk云说
跨境电商导航
WordPress啦
站长专题
网站推广
网站程序
网站赚钱
虚拟主机
cPanel
网址导航专题
云计算
微博营销
虚拟主机管理系统
开放平台
WIKI程序与应用
美国十大主机
编辑“
WordPress设计Error 404页面
”(章节)
人物百科
|
营销百科
|
网赚百科
|
站长工具
|
网站程序
|
域名主机
|
互联网公司
|
分类索引
跳转至:
导航
、
搜索
警告:
您没有登录。如果您做出任意编辑,您的IP地址将会公开可见。如果您
登录
或
创建
一个账户,您的编辑将归属于您的用户名,且将享受其他好处。
反垃圾检查。
不要
加入这个!
==404.php高级示例== 下面这个例子展示了WordPress 404.php页面和HTTP状态码操作的技术高度。我们也应该尽最大努力让404页面为访问者提供更有效的信息,尽可能将断链重定向到正确位置上。 [http://wordpress.org/extend/plugins/askapache-google-404/ AskApache Google 404 Plugin]插件能够处理404.php模板文件所处理的其它类型错误状态码。 插件决定[[服务器]]错误信息的类型,这样我们就可以为非404错误提供准确的http反应,不必浪费带宽和CPU。插件也能够根据HTTP状态码和[http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.1.1 RFC 2616 specifications]中的规定尽力提供正确反应。 <?php $ASKAPACHE_S_C = array('400' => array('Bad Request', 'Your browser sent a request that this server could not understand.'),'401' => array( 'Authorization Required', 'This server could not verify that you are authorized to '. 'access the document requested. Either you supplied the '. 'wrong credentials (e.g., bad password), or your browser '. 'doesn\'t understand how to supply the credentials required.'),'402' => array('Payment Required','INTERROR'),'403' => array('Forbidden','You don\'t have permission to access THEREQUESTURI on this '.'server.'),'404' => array( 'Not Found', 'We couldn\'t find <acronym title="THEREQUESTURI">that uri'. '</acronym> on our server, though it\'s most certainly not '. 'your fault.'),'405' => array( 'Method Not Allowed', 'The requested method THEREQMETH is not allowed for the URL '. 'THEREQUESTURI.'),'406' => array( 'Not Acceptable', 'An appropriate representation of the requested resource '. 'THEREQUESTURI could not be found on this server.'), '407' => array( 'Proxy Authentication Required', 'This server could not verify that you are authorized to '. 'access the document requested. Either you supplied the wrong '. 'credentials (e.g., bad password), or your browser doesn\'t '. 'understand how to supply the credentials required.'),'408' => array( 'Request Time-out', 'Server timeout waiting for the HTTP request from the client.'),'409' => array( 'Conflict', 'INTERROR'),'410' => array( 'Gone', 'The requested resourceTHEREQUESTURIis no longer available on '. 'this server and there is no forwarding address. Please remove '. 'all references to this resource.'),'411' => array( 'Length Required', 'A request of the requested method GET requires a valid '. 'Content-length.'),'412' => array( 'Precondition Failed', 'The precondition on the request for the URL THEREQUESTURI '. 'evaluated to false.'),'413' => array( 'Request Entity Too Large', 'The requested resource THEREQUESTURI does not allow request '. 'data with GET requests, or the amount of data provided in the '. 'request exceeds the capacity limit.'),'414' => array( 'Request-URI Too Large', 'The requested URL\'s length exceeds the capacity limit for '. 'this server.'),'415' => array( 'Unsupported Media Type', 'The supplied request data is not in a format acceptable for '. 'processing by this resource.'),'416' => array( 'Requested Range Not Satisfiable', ''),'417' => array( 'Expectation Failed', 'The expectation given in the Expect request-header field could '. 'not be met by this server. The client sent <code>Expect:</code>'),'422' => array( 'Unprocessable Entity', 'The server understands the media type of the request entity, but '. 'was unable to process the contained instructions.'),'423' => array( 'Locked', 'The requested resource is currently locked. The lock must be released '. 'or proper identification given before the method can be applied.'),'424' => array( 'Failed Dependency', 'The method could not be performed on the resource because the requested '. 'action depended on another action and that other action failed.'),'425' => array( 'No code', 'INTERROR'),'426' => array( 'Upgrade Required', 'The requested resource can only be retrieved using SSL. The server is '. 'willing to upgrade the current connection to SSL, but your client '. 'doesn\'t support it. Either upgrade your client, or try requesting '. 'the page using https://'),'500' => array( 'Internal Server Error', 'INTERROR'),'501' => array( 'Method Not Implemented', 'GET to THEREQUESTURI not supported.'),'502' => array( 'Bad Gateway', 'The proxy server received an invalid response from an upstream server.'),'503' => array( 'Service Temporarily Unavailable', 'The server is temporarily unable to service your request due to '. 'maintenance downtime or capacity problems. Please try again later.'),'504' => array( 'Gateway Time-out', 'The proxy server did not receive a timely response from the '. 'upstream server.'),'505' => array( 'HTTP Version Not Supported', 'INTERROR'),'506' => array( 'Variant Also Negotiates', 'A variant for the requested resource <code>THEREQUESTURI</code> '. 'is itself a negotiable resource. This indicates a configuration error.'),'507' => array( 'Insufficient Storage', 'The method could not be performed on the resource because the '. 'server is unable to store the representation needed to successfully '. 'complete the request. There is insufficient free space left in your '. 'storage allocation.'),'510' => array( 'Not Extended', 'A mandatory extension policy in the request is not accepted by the '. 'server for this resource.') ); // prints out the html for the error, taking the status code as input function aa_print_html ($AA_C){ global $AA_REQUEST_METHOD, $AA_REASON_PHRASE, $AA_MESSAGE; if($AA_C == '400'||$AA_C == '403'||$AA_C == '405'||$AA_C[0] == '5'){ @header("Connection: close",1); if($AA_C=='405')@header('Allow: GET,HEAD,POST,OPTIONS,TRACE'); echo "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n< html>< head>"; echo "< title>$AA_C $AA_REASON_PHRASE< /title>"; echo "< h1> $AA_REASON_PHRASE< /h1>< p>$AA_MESSAGE< br>< /p>< /body>< /html>"; return true; } else return false; } // Tries to determine the error status code encountered by the server if(!isset($_REQUEST['error'])) $AA_STATUS_CODE = '404'; else $AA_STATUS_CODE = $_REQUEST['error']; if(isset($_SERVER['REDIRECT_STATUS']) && $_SERVER['REDIRECT_STATUS']!='200') $AA_STATUS_CODE = $_SERVER['REDIRECT_STATUS']; $AA_REQUEST_METHOD = $_SERVER['REQUEST_METHOD']; $AA_THE_REQUEST = htmlentities(strip_tags($_SERVER['REQUEST_URI'])); $AA_REASON_PHRASE = $ASKAPACHE_S_C[$AA_STATUS_CODE][0]; $AA_M_SR=array(array('INTERROR','THEREQUESTURI','THEREQMETH'), array('The server encountered an internal error or misconfiguration '. 'and was unable to complete your request.',$AA_THE_REQUEST,$AA_REQUEST_METHOD)); $AA_MESSAGE=str_replace($AA_M_SR[0],$AA_M_SR[1],$ASKAPACHE_S_C[$AA_STATUS_CODE][1]); // begin the output buffer to send headers and resonse ob_start(); @header("HTTP/1.1 $AA_STATUS_CODE $AA_REASON_PHRASE",1); @header("Status: $AA_STATUS_CODE $AA_REASON_PHRASE",1); if(!aa_print_html($AA_STATUS_CODE)){ ?> <?php get_header();?> < div id="content"> < div class="post"> < h1><?php _e("$AA_STATUS_CODE $AA_REASON_PHRASE"); ?>< /h1> <?php if(function_exists('aa_google_404')) aa_google_404(); ?> < /div> < /div> <?php get_sidebar(); ?> <?php get_footer(); ?> <?php } exit; exit(); ?>
摘要:
请注意,您对站长百科的所有贡献都可能被其他贡献者编辑,修改或删除。如果您不希望您的文字被任意修改和再散布,请不要提交。
您同时也要向我们保证您所提交的内容是您自己所作,或得自一个不受版权保护或相似自由的来源(参阅
Wordpress-mediawiki:版权
的细节)。
未经许可,请勿提交受版权保护的作品!
取消
编辑帮助
(在新窗口中打开)