[wp-trac] [WordPress Trac] #11348: Archive Page Should be 404.php When !have_posts()

WordPress Trac wp-trac at lists.automattic.com
Mon Jan 11 06:05:58 UTC 2010

#11348: Archive Page Should be 404.php When !have_posts()
 Reporter:  miqrogroove   |        Owner:  ryan    
     Type:  defect (bug)  |       Status:  reopened
 Priority:  normal        |    Milestone:  2.9     
Component:  Query         |      Version:  2.8.4   
 Severity:  normal        |   Resolution:          
 Keywords:                |  

Comment(by filosofo):

 Replying to [comment:10 miqrogroove]:
 > >  The meaning of the query /category/iamempty/ is that it requests the
 category named "iamempty."
 > Except that is not the meaning.  The meaning can be customized.  The
 default meaning is that it requests the posts in the category.

 How do you figure?  What you're saying sounds a lot like the fallacy of
 composition.  Besides, a typical category rewrite rule in WP looks like

 'category/(.+?)/?$' =>

 That seems to be saying that a query for {{{/category/iamempty/}}} is a
 query for the category named "iamempty."  Common sense says the same

 In wp-includes/classes.php, we see that a query starts out as an assumed
 404 until it matches an object:

  148 // If we match a rewrite rule, this will be cleared.
  149 $error = '404';

 Of course the query {{{/category/iamempty/}}} matches the rule given
 above, so then the following comes into play when WP_Query shows that
 there are no posts in category "iamempty":

  463   // Don't 404 for these queries if they matched an object.
  464   if ( ( is_tag() || is_category() || is_author() ) &&
           $wp_query->get_queried_object() ) {
  465           if ( !is_404() )
  466                   status_header( 200 );
  467           return;
  468   }

 Note how the category is considered the ''queried object'' (and for a
 ''non-existent'' queried object, {{{$wp_query->get_queried_object()}}}
 returns null).  And also, note the analogy to an author's page: would you
 consider an author's page non-existent just because she hadn't yet written
 any posts?

 > When the category is empty, no links for the category exist, the
 category is hidden.

 greenshady already proved this false, above:
   WordPress will also link to a category without posts using:
   {{{ wp_list_categories( array( 'hide_empty' => false ) ); }}}


 > On a test server, I can make a directory with nothing in it.  If I click
 on the index link it will respond 200 with no files listed.  If I then
 hide the directory, the index link disappears, and the server responds 404
 at the URL for the directory.  Now by your explanation above, that means
 my server goes "against the HTTP 404 definition" because the empty
 category is an existing resource, even though it is empty and hidden.


 Please refer again to the definition of a 404 response: "The server has
 not found anything matching the Request-URI."  If you've ''hidden'' a file
 from the web server, then it can't find it, can it?

 And I really don't understand why you think a ''hidden'' directory is
 analogous to an ''empty'' category.  Thankfully in real life my ''empty''
 glass isn't ''hidden''; otherwise the waiter would never get me a refill!


 > I wonder, why did the authors of a web server not go out their way to
 ensure that an empty hidden resource respond with 200?


 Don't conflate "hidden" and "empty," as they're obviously not the same
 (even to Apache).  As you pointed out above:

   On a test server, I can make a directory with nothing in it.  If I click
 on the index link it will respond 200 with no files listed.

Ticket URL: <http://core.trac.wordpress.org/ticket/11348#comment:12>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software

More information about the wp-trac mailing list