Make WordPress Core

Opened 16 years ago

Closed 14 years ago

Last modified 14 years ago

#2996 closed enhancement (wontfix)

Content-managed error pages (particularly for 404 errors)

Reported by: wnicholls's profile wnicholls Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Administration Keywords:
Focuses: Cc:


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?


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

Change History (8)

#1 @RuddO
16 years ago

Sorry for my butting in, but, actually what should happen is that WP should supply the standard 404 Not Found page, just like it does all the time, without needing any configuration. The thing is, you don't need an extra option at all. But it seems that #2515 is breaking the standard 404 handling.

#2 @wnicholls
16 years ago

  • Summary changed from Add option for special page ('404') when URL does not match any page or post to Content-managed error pages (particularly for 404 errors)

RuddO: yes you're right, I got a bit confused because I started writing this as a comment on #2515 but changed my mind halfway through, decided this was a separate enhancement.

404 pages are of course well-documented at, but as I understand it that doesn't allow editing of the page content in Wordpress, unless the theme author codes in some kind of get_post() call. A full-blown "page" object would be very useful: it could still use a custom template (in fact that may be desirable).

I do realise on thinking this through that there may be real ramifications for this (eg broken themes), but that's why I logged this as an enhancement separate to other tickets.

#3 @RuddO
16 years ago

Ok, I know what you want. In fact, I have WP-managed error documents on my blog.

First off, let me tell you: the standard 404 page can be themed. Of course, if you're accessing an existing directory, WP won't work because since the directory exists, WP's engine doesn't kick in.

I coded a workaround on my RevvedUp and Burnin' R themes: and They add ErrorDocument directives to .htaccess so, instead of showing the standard Apache error document, they call index.php?error=[errorcode]. Some elbow grease in the themes' functions.php and index.php detect this argument and show a proper error page, that ranges in the 400 and 500 HTTP error domains.

Of course, if this were moved to core WP (and made themeable), it wouldn't be such a bad idea.

My themes also theme the Apache directory listings.

#4 @matt
15 years ago

  • Milestone changed from 2.1 to 2.2

#5 @foolswisdom
15 years ago

  • Milestone changed from 2.2 to 2.4

#6 @pishmishy
14 years ago

  • Resolution set to wontfix
  • Status changed from new to closed

This ticket hasn't seen much activity, can only presume that not many people are interested in being able to define a 404 page from within WordPress. RuddO lists a work around for those who really do. Resolving as wontfix.

#7 @Nazgul
14 years ago

  • Milestone 2.4 deleted

#8 @Viper007Bond
14 years ago

Just make a 404.php file in your theme's directory. It will be served rather than index.php for 404's.

Note: See TracTickets for help on using tickets.