Opened 17 years ago
Closed 16 years ago
#2409 closed defect (bug) (fixed)
wordpress errors return status 200
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 2.3 | Priority: | normal |
Severity: | normal | Version: | 2.0.1 |
Component: | General | Keywords: | has-patch 2nd-opinion |
Focuses: | Cc: |
Description
Wordpress notices when a page doesn't exist or the database is down and
returns a human-readable error. However, the HTTP status code for these
pages remains 200. This means the page looks like a "real" page to
monitoring systems and programs like wget.
This bug is to request a change to the themes/default/404.php file and wp-includes/wp-db.php
file. Basically wordpress should call the php header() function to set the return
header when there is an error.
Here are the diffs that will accomplish this:
Index: wp-includes/wp-db.php =================================================================== --- wp-includes/wp-db.php (revision 420) +++ wp-includes/wp-db.php (working copy) @@ -42,6 +42,7 @@ function wpdb($dbuser, $dbpassword, $dbname, $dbhost) { $this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword); if (!$this->dbh) { + header('HTTP/1.0 500 Database Not Available'); $this->bail(" <h1>Error establishing a database connection</h1> <p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can't contact the database server at <code>$dbhost</code>. This could mean your host's database server is down.</p> Index: wp-content/themes/default/404.php =================================================================== --- wp-content/themes/default/404.php (revision 420) +++ wp-content/themes/default/404.php (working copy) @@ -1,3 +1,4 @@ +<?php header('HTTP/1.0 404 Not Found'); ?> <?php get_header(); ?> <div id="content" class="narrowcolumn">
Attachments (3)
Change History (22)
#2
@
17 years ago
- Owner changed from anonymous to markjaquith
- Status changed from new to assigned
+1 for the idea
+1 for Nathan's suggestion of putting the 500 error in wpdb::bail();
#3
@
17 years ago
- Keywords bg|has-patch added
- Milestone set to 2.1
Patch adds 500 error to wpdb::bail()
I also modified status_header() to accept 500 and also to optionally accept alternative $text messages.
Adding header() to the top of a template file is a bad idea, however... and that's really a separate issue than WP errors.
#4
@
17 years ago
- Keywords has-patch 2nd-opinion added; bg|has-patch removed
Any thoughts on this patch?
#5
@
17 years ago
Perhaps we should include a general Status Code -> Message lookup array, pulled from the RFCs. So we can feel comfortable passing anything into it.
#8
@
17 years ago
This should be a 503 Service Unavailable error, not a 500 Internal Server Error. 500's are generally reserved for Web server configuration errors (i.e. Perl permissions, .htaccess/httpd.conf errors).
#9
@
17 years ago
Patch attached which replaces MarkJaquith's: send a 503 and include a resp code -> message array in vars.php with an accessor func, header_num_to_desc().
#11
@
17 years ago
leflo commented in #3166 that it will not fix this issue. "It won't fix anything where wp_redirect isn't called."
#16
@
16 years ago
Okay, new patch does everything. Not so sure about the placing of the 404 one in WP_Query, though.
The wp-db.php error should be in wpdb::bail(), I think, instead of right before the function is called (or a standalone error handling class, really, but that's a different problem).