[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.
 [[br]]

 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
 this:

 {{{
 'category/(.+?)/?$' =>
 'index.php?category_name=$matches[1]'
 }}}

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

 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?
 [[br]]
 [[br]]

 > 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 ) ); }}}

 [[br]]

 > 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.

 [[br]]

 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!

 [[br]]
 [[br]]

 > 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?

 [[br]]

 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