[wp-trac] [WordPress Trac] #2996: Add option for special page ('404') when URL does not match any page or post

WordPress Trac wp-trac at lists.automattic.com
Thu Aug 3 00:50:54 GMT 2006


#2996: Add option for special page ('404') when URL does not match any page or
post
----------------------------+-----------------------------------------------
 Reporter:  wnicholls       |       Owner:  anonymous
     Type:  enhancement     |      Status:  new      
 Priority:  normal          |   Milestone:  2.1      
Component:  Administration  |     Version:           
 Severity:  normal          |    Keywords:           
----------------------------+-----------------------------------------------
 What I mean is probably best shown by example.

 Say I have a site where Wordpress is installed in the root, acting
 primarily as a CMS, not as a blog site (although actually this really has
 no bearing on this request). Or IOW its primary purpose is to serve pages,
 not posts.

 For illustration I also have a subdirectory '''/nonwp''' (under the root)
 which contains static HTML files not managed by Wordpress (this works
 because the .htaccess rewrite rules test for file/directories that exist
 before passing to index.php)

 The site's home page http://mysite/ is a page, not a list of posts, thus
 using the new feature of #2515 to set a front page thus:

 {{{
   get_option('show_on_front') == 'page'
   get_option('page_on_front') == '/home' (well, the page id of it)
   get_option('page_for_posts') == '/blog' (page id again)
 }}}

 So depending on the URL visited:
 {{{
   http://mysite/                  -> the "front" page
   http://mysite/home/             -> also the "front" page (identical
   http://mysite/about/            -> another page
   http://mysite/blog/             ->  posts page
   http://mysite/nonwp/index.html  -> these files actually exist, so the
 .htaccess  rewrite rules don't pass on to wordpress
 }}}

 But what about these URLs?
 {{{
   http://mysite/thisdoesnotexist/
   http://mysite/about/notexist/
   http://mysite/nonwp/notexist.html
 }}}

 As it stands these will all display POSTS. This is highly undesirable. I
 want it to show some kind of '404' page.  At worst it should show the
 'front' page as per #2515

 The administration side of this would be pretty simple - add get_option(
 'page_for_bad_url' ) == page id, or something (this could be the posts
 page, could be the front page, could be 'none'.  With the appropriate
 editing in '''wp-admin/options_reading.php'''.

 The engine side is a bit harder. The code in '''query.php''' is pretty
 hairy, and I can't work out exactly how to patch this, someone with
 familiarity of the code might be able to suggest.

 I was thinking something along these lines ..
 {{{
 $request = " SELECT ... FROM $wpdb->posts ...";
 ...
 $this->posts = $wpdb->get_results($this->request);
 if( count($this->posts) == 0 and get_option('404_page') )
 {
    page_id = get_option('404_page')
    go back and try querying again
 }
 }}}
 Of course it isn't quite that simple

-- 
Ticket URL: <http://trac.wordpress.org/ticket/2996>
WordPress Trac <http://wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list