Support » Fixing WordPress » 404 error shows all pages’ contents

  • Resolved gpaciga

    (@gpaciga)


    When my blog is supposed to show a 404 error, it displays the content of all my static pages at once. I have no idea what I did to cause it. I have been playing a lot with using static pages, plugins, and page templates, but I have no idea where to look to fix this problem. Can anybody help me diagnose this? For an example of what’s happening see http://www.booberfish.com/thispagedoesnotexist

Viewing 8 replies - 1 through 8 (of 8 total)
  • That page turned out to be very, very long. Unless you have a bunch of static pages, I think that whatever page WP is using, it’s grabbing all posts and pages (they’re all stored in the same table).

    Do you have a file in your theme folder named “404.php”? If so, just rename it to “old-404.php” — then try that URL again. Does the problem still occur?

    If you’re not using a 404.php file, then WP is using the theme’s index.php as a fallback.

    I’m thinking that (1) there’s some custom query (using query_posts or get_posts) that is calling all posts or (2) your blog is set to show all posts on a page (Settings – Reading – Blog pages show at most — is set to “-1”) — though “www.booberfish.com/blog/” only has twelve posts and has links for older pages.

    Thread Starter gpaciga

    (@gpaciga)

    I have 69 static pages, a few of which are quite long by themselves. It is only pages that show up, not posts. The front page at booberfish.com is a static page and posts are shown with a special template page, but that was set up and working fine long before this happened.

    My theme does have a 404.php but I hadn’t changed it, and removing it didn’t help. I suspect it is some ill-formed query at work… I dug around for something along those lines, but nothing turned up. It’s not the .htaccess file, the plugins, or the theme.

    I tried using wget to request a page that doesn’t exist. It reported a 301 Moved Permanently, then requested the same address with a slash on the end , which returns 200 OK. If I request something with a slash on the end it just says 200 OK.

    I tried using wget to request a page that doesn’t exist. It reported a 301 Moved Permanently, then requested the same address with a slash on the end , which returns 200 OK. If I request something with a slash on the end it just says 200 OK.

    Unless a theme’s 404.php template contains the proper code, WP will always return a 200 message for the 404 page (see the Codex page on creating a 404 page). And the no-slash redirect to correct ‘slash’ permalink is also normal WP behavior (since 2.3 or so).

    I dug around for something along those lines, but nothing turned up. It’s not the .htaccess file, the plugins, or the theme.

    So I and others can be sure, please answer the following questions:

    1. Have you checked your theme’s folder to make sure the files are in their proper spot and named correctly (including all lower-case letters) — see the Codex page on the Template Hierarchy.

    Does this happen after you…
    2. …disabled all plugins?
    3. …removed all the widgets from your sidebar?
    4. …switched to a default theme?

    If the problem still occurs, then export your site from the Admin panel , back up your database, and backup your site’s files. Then remove all of the old WP files and reinstall WordPress, using your old database.

    If the problem still occurs, then create a fresh database for your WP install. If the problem still occurs, then there’s probably a conflict between WP and the server setup of your site (MySQL version, PHP, et cetera).

    ***

    Another debugging option: To see exactly what queries your WP install is doing, add the following two lines to your wp-config file

    /* save database queries for debugging */
    define('SAVEQUERIES', true);

    And add this PHP snippet to your theme’s footer:

    <?php if (SAVEQUERIES) {
    global $wpdb;
    echo '<!--\n';
    print_r($wpdb->queries);
    echo '\n--!>';
    } ?>

    I posted a sample set of queries at the pastebin: http://wordpress.pastebin.ca/1034713. Ignore the queries for options and compare the SELECT statements that query your wp_posts table.

    Thread Starter gpaciga

    (@gpaciga)

    1. I’m not sure about the hierarchy… but I made the theme just by copying the default one and tweaking it to suit my needs. The 404 page worked fine with the changes I made, and the only thing I changed since then is adding some page templates (by the names gallery.php and nosidebar.php).

    2. It still happens with all plugins deactivated.

    3. I have no sidebar widgets.

    4. Default theme has the same problem.

    I also saved the queries, with default theme and no plugins, and put them here: http://www.booberfish.com/queries-default.txt (the pastebin site refuses to load right now…). I noticed there was nothing about a 404 permalink like in your example, but I do have two requests that seem to reference all my pages: wp_get_obect_terms and update_postmeta_cache. There’s also one from get_pages that is asking for all published pages. How can I find where that is being called?

    There’s also one from get_pages that is asking for all published pages. How can I find where that is being called?

    You’ll need to examine the theme’s files and look for any template tags that would query your blog’s database: query_posts, get_posts, maybe a wp_list_pages. Perhaps check to see if you’re using any deprecated functions.

    While looking at the source of the 404 results page, I saw this:

    In the end I wrote a plugin from scratch to do it for me. It’s not something I’d share as it has a lot of hard coded details applicable only to Booberfish, and it’s incomplete since not all my static pages are under WP control, but I’m pretty happy with it.

    Did you deactivate that, too? (Just checking)

    Unless someone else can swoop in with another opinion, it looks like reinstalling your WP installation is the next step.

    (BTW, you should remove that text document or at least edit query # “[3]”)

    Thread Starter gpaciga

    (@gpaciga)

    My custom plugins were the first suspect, and the first to go. It still happens with them deactivated. They can’t do anything while deactivated can they?

    I checked all the WordPress files and they have not been changed at all from those distributed with 2.5.1. To be sure I deleted and uploaded them again. That didn’t work.

    So I dumped my whole database, installed WordPress again. Then when requesting a page that doesn’t exist, I was just shown the homepage again, both with the default theme and my custom theme. While this isn’t the same behaviour, it still wasn’t a 404 error page. From what I remember reading if a theme doesn’t have a 404.php then it just goes back to the homepage, but both these these *do* have a 404.php, so something still seems wrong.

    From what I can tell it’s not plugins, it’s not the theme, it’s not the core files, and it’s not the database. I’ll contact my host and see if they changed anything on the server. What else could it be at this point?

    I should have checked Trac, sooner (my bad). This looks like a WP bug…

    Trac Ticket #6539:

    If an installation is configured to have the home page set to a static page, with the “Front page” set but the “Posts page” unset, instead of the 404 template showing up when necessary, all pages are loaded and displayed.

    (See also #6803)

    On my test site (Windows, Apache 2.2.x, PHP 5.2.5), I tried that and I could duplicate your problem. Then, setting the “Posts page” fixed the issue.

    You are using a static front page, right? If so, see if setting the “Posts page” to some page fixes the problem. If not, read through the #6539 ticket and try to apply one of the patches.

    Thread Starter gpaciga

    (@gpaciga)

    Thanks for finding that. I applied the patch given there to fix the problem (basically just correcting what looks like a typo in query.php).

    Setting a “Posts page” brought up other problems, though, so I’m leaving it unset. I’m not sure what what it’s supposed to do. I have blank page with a special template to display my posts (at /blog/) and interestingly—I just noticed this a couple hours ago—the 404 page did come up properly when requesting a page like /blog/thisisnotapage.

    Anyway, this seems to be resolved. Thanks again for your help.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘404 error shows all pages’ contents’ is closed to new replies.