[wp-trac] [WordPress Trac] #14880: 404 Errors Replaced with Category Pages
WordPress Trac
wp-trac at lists.automattic.com
Mon Nov 8 11:08:40 UTC 2010
#14880: 404 Errors Replaced with Category Pages
---------------------------+------------------------------------------------
Reporter: askapache | Owner: scribu
Type: defect (bug) | Status: reopened
Priority: normal | Milestone: 3.1
Component: Query | Version: 3.1
Severity: major | Resolution:
Keywords: parse_request |
---------------------------+------------------------------------------------
Comment(by askapache):
Also broken, even when setting up apache to explicitly set that the
errordocument should be shown by using:
{{{
ErrorDocument /index.php?error=404
Redirect 404 /show-error-404
}}}
And requesting /show-error-404, it still does not display the 404 error
page. I have created a 404.php that works with wordpress, phpbb,
basically any system that can run php 4/5 including windows to handle all
HTTP errors. It's being used by over 20,000 wordpress users as its
included in the plugin askapache-google-404.
Here is the function from the askapache-google-404 plugin, which is the
most advanced and complete php http error-handling code on the net.
Something very close to that added to WP core would be incredibly awesome.
{{{
class AA_G404_Handler {
var $reason = '';
var $uri = '';
var $sc;
var $msg = '';
var $ASC = array(
400 => "Your browser sent a request that this server could
not understand.",
401 => "This server could not verify that you are
authorized to access the document requested.",
402 => '',
403 => "You don't have permission to access %U% on this
server.",
404 => "We couldn't find <acronym title='%U%'>that
uri</acronym> on our server, though it's most certainly not your fault.",
405 => "The requested method %M% is not allowed for the
URL %U%.",
406 => "An appropriate representation of the requested
resource %U% could not be found on this server.",
407 => "An appropriate representation of the requested
resource %U% could not be found on this server.",
408 => "Server timeout waiting for the HTTP request from
the client.",
409 => '',
410 => "The requested resource %U% is no longer available
on this server and there is no forwarding address. Please remove all
references to this resource.",
411 => "A request of the requested method GET requires a
valid Content-length.",
412 => "The precondition on the request for the URL %U%
evaluated to false.",
413 => "The requested resource %U% does not allow request
data with GET requests, or the amount of data provided in the request
exceeds the capacity limit.",
414 => "The requested URL's length exceeds the capacity
limit for this server.",
415 => "The supplied request data is not in a format
acceptable for processing by this resource.",
416 => 'Requested Range Not Satisfiable',
417 => "The expectation given in the Expect request-header
field could not be met by this server. The client sent
<code>Expect:</code>",
422 => "The server understands the media type of the
request entity, but was unable to process the contained instructions.",
423 => "The requested resource is currently locked. The
lock must be released or proper identification given before the method can
be applied.",
424 => "The method could not be performed on the resource
because the requested action depended on another action and that other
action failed.",
425 => '',
426 => "The requested resource can only be retrieved using
SSL. Either upgrade your client, or try requesting the page using
https://",
500 => '',
501 => "%M% to %U% not supported.",
502 => "The proxy server received an invalid response from
an upstream server.",
503 => "The server is temporarily unable to service your
request due to maintenance downtime or capacity problems. Please try again
later.",
504 => "The proxy server did not receive a timely response
from the upstream server.",
505 => '',
506 => "A variant for the requested resource
<code>%U%</code> is itself a negotiable resource. This indicates a
configuration error.",
507 => "The method could not be performed. There is
insufficient free space left in your storage allocation.",
510 => "A mandatory extension policy in the request is not
accepted by the server for this resource."
);
/**
*/
function AA_G404_Handler(){}
/**
*/
function handle_it()
{
global $AA_G404, $wp_did_header,
$wp_did_template_redirect, $wp_query, $wp_rewrite, $wpdb, $wp_version,
$wp, $id, $comment, $user_ID;
if (is_array($wp_query->query_vars))
extract($wp_query->query_vars, EXTR_SKIP);
// reset AA_G404_Handler vars
$this->uri = $this->sc = $this->msg = $this->reason = '';
$this->uri =
esc_attr(stripslashes($_SERVER['REQUEST_URI']));
$this->sc = absint((isset($_SERVER['REDIRECT_STATUS']) &&
$_SERVER['REDIRECT_STATUS'] != 200) ? $_SERVER['REDIRECT_STATUS'] :
(!isset($_REQUEST['error'])) ? 404 : $_REQUEST['error']);
if ('HTTP/1.1' != $_SERVER["SERVER_PROTOCOL"] &&
'HTTP/1.0' != $_SERVER["SERVER_PROTOCOL"] && $_SERVER["SERVER_PROTOCOL"] =
'HTTP/1.0') $this->sc = 505;
$this->reason = get_status_header_desc($this->sc);
if ($this->sc == 402 || $this->sc == 409 || $this->sc ==
425 || $this->sc == 500 || $this->sc == 505) $this->msg = 'The server
encountered an internal error or misconfiguration and was unable to
complete your request.';
else $this->msg = (array_key_exists($this->sc, $this->ASC)
!== false) ? str_replace(array('%U%', '%M%'), array($this->uri,
$_SERVER['REQUEST_METHOD']), $this->ASC["{$this->sc}"]) : 'Error';
if ($this->sc == 400 || $this->sc == 403 || $this->sc ==
405 || floor($this->sc / 100) == 5) {
if ($this->sc == 405) @header('Allow:
GET,HEAD,POST,OPTIONS,TRACE', 1, 405);
echo "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML
2.0//EN\">\n<html><head>\n<title>{$this->sc}
{$this->reason}</title>\n<h1>{$this->reason}</h1>\n<p>{$this->msg}<br
/>\n</p>\n</body></html>";
return false;
}
@header("{$_SERVER['SERVER_PROTOCOL']} {$this->sc}
{$this->reason}", 1, $this->sc);
@header("Status: {$this->sc} {$this->reason}", 1,
$this->sc);
@header("Connection: close", 1);
}
/**
*/
function output()
{
global $AA_G404;
// if aa_google_404 function called from within template
but plugin not enabled, ditch
if('1' != $AA_G404->options['enabled']) return '';
$google_helper = (($AA_G404->options['google_404'] == '1')
? '<script type="text/javascript"
src="http://linkhelp.clients.google.com/tbproxy/lh/wm/fixurl.js"></script>'
. "\n" : '');
$recent = (($AA_G404->options['recent_posts'] == '1') ?
'<ul>' . wp_get_archives(array('echo' => false, 'type' => 'postbypost',
'limit' => absint($AA_G404->options['recent_num']))) . '</ul>' : '');
$related = (($AA_G404->options['related_posts'] == '1') ?
$this->related_posts((int)$AA_G404->options['related_num'],
(int)$AA_G404->options['related_length']) : '');
$tag_cloud = (($AA_G404->options['tag_cloud'] == '1') ?
'<p>' . wp_tag_cloud(array('echo' => false)) . '</p>' : '');
$sr = array(
'%error_title%' => $this->sc . ' ' .
$this->reason,
'%related_posts%' => $related,
'%recent_posts%' => $recent,
'%google_helper%' => $google_helper,
'%tag_cloud%' => $tag_cloud,
);
if ($AA_G404->options['google_ajax'] == '1') echo
str_replace(array_keys($sr), array_values($sr), $AA_G404->code['html']);
if ($AA_G404->options['mobile_analytics_log'] == '1')echo
$this->mobile_tracker_image();
}
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/14880#comment:18>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list