I am trying to debug an intermittent 404 issue that may be related to BBPress. I’ve read several other reports about intermittent 404s and BBPress, but none of them are exactly applicable to my situation, so I’m asking a new question.

The main page of my website will intermittently load with a 404.The intermittent access issue appears to last between 10 seconds and 3 minutes at a time. When this happens, it’s down for everyone trying to access the site (confirmed while on the phone with hosting service tech support). Other pages on the site appear to load correctly during this time window. Hitting refresh will eventually successfully reload the page correctly.

I am using Query Monitor to examine the rewrite rules. Here are the results when the page is loading incorrectly:

Request account-2/conscious-business-design-dashboard
Matched Rule    [^/]+/([^/]+)/?$
Matched Query   attachment=conscious-business-design-dashboard
Query String    attachment=conscious-business-design-dashboard
Query Vars  attachment  conscious-business-design-dashboard
comments_per_page   50
name    conscious-business-design-dashboard
order   DESC
posts_per_page  10
update_post_meta_cache  1
update_post_term_cache  1

Here are the results when the page is loading correctly:

Request account-2/conscious-business-design-dashboard
Matched Rule    (.?.+?)(?:/([0-9]+))?/?$
Matched Query   pagename=account-2%2Fconscious-business-design-dashboard
Query String    pagename=account-2%2Fconscious-business-design-dashboard
Query Vars  comments_per_page   50
name    conscious-business-design-dashboard
order   DESC
pagename    conscious-business-design-dashboard
posts_per_page  10
update_post_meta_cache  1
update_post_term_cache  1
Queried Object  
Single Page: #225 (WP_Post)

Here is the most relevant query that is being run during the 404:

SELECT wp_posts.*
FROM wp_posts 
WHERE 1=1 
AND wp_posts.post_name = 'conscious-business-design-dashboard'
AND wp_posts.post_type = 'attachment' 
ORDER BY wp_posts.post_date DESC 

Here is the query run when the page successfully loads:

SELECT wp_posts.*
FROM wp_posts 
WHERE 1=1 
AND (wp_posts.ID = '225')
AND wp_posts.post_type = 'page' 
ORDER BY wp_posts.post_date DESC 

When I look at the BBPress code, I can identify the rewrite rules here:

// Rewrite rule matches used repeatedly below
    $root_rule    = '/([^/]+)/?$';
    $feed_rule    = '/([^/]+)/' . $feed_slug  . '/?$';
    $edit_rule    = '/([^/]+)/' . $edit_slug  . '/?$';
    $paged_rule   = '/([^/]+)/' . $paged_slug . '/?([0-9]{1,})/?$';

However, all slugs are correctly set in the database, and I can’t figure out how they might be getting corrupted. I cannot find the exact rewrite rule listed in the Query Monitor results in either core or plugin code.

Additional information:

  • the site is using SSL and pretty permalinks are enabled.
  • I have not been able to replicate the issue on a test server on a different hosting service, either with or without SSL enabled. The staging server on the primary host is also not showing 404s. The test server is a VPS, but is also running enough other sites to approximate a full load. The load on the primary server directly is small (tens of users concurrently), but the primary site is shared hosting.
  • I have uptimerobot monitoring showing precisely a 3 hour downtime twice in the last 24 hours, but the access logs are not showing the 5 minute access expected for uptimerobot, so I'm not sure how accurate those numbers are. (I'm trying to eliminate the possibility of a CPU overload, since the 404s seem to be both transient and time-linked across all users. Up for everyone, then suddenly briefly down for everyone.)
  • The primary site is a membership site and is live, so "turn off all plugins" is not really an option (we'd ditch the forum first)-- also, with plugins turned off, we would not be able to replicate the load to force the 404 to happen again. The membership rules (MemberPress) are currently reliant on pretty permalinks. The membership plugins are MemberPress and LearnDash
  • The site is also running BuddyPress, which some research I did indicated might also be involved. It sounds like in some cases, visiting pages in specific orders may trigger a BuddyPress rewrite rule 404, but I am relatively certain that in my case, the issue is not dependent on page order of visits. (I have referer logs from 404 Error Monitor.)
  • I have installed the plugins Query Monitor (providing the data in this question) and 404 Error Monitor (which lists pages other than the home page of the site as showing 404s, but the access log only shows 404s on the main page). I have not installed Debug Bar because their support forum is showing incompatibility with current versions of WP.
  • I am not 100% certain if the issue is confined to the main page of the website. Access logs say yes. 404 Error Monitor is showing a large list of other pages that are experiencing 404s. I think I have seen it on other pages, but I can't swear to it. I can verify that at the exact point that the main page was down for both me and hosting tech support, I was able to access other pages on the site.
  • The main page does not contain either BuddyPress or BBPress functionality on it. It's got an embedded Vimeo video, a few buttons, plain text, images, and a series of MemberPress access rules showing/hiding content.

Any suggestions for further troubleshooting?

  • I didn't call it out explicitly, but it's probably obvious that one of the issues is that the page is trying to load as an attachment during the 404. I haven't figured out what's going on with that yet. – buzzo Jan 29 '16 at 20:27

There's a known issue with LearnDash and bbPress/BuddyPress which can cause this, I ran into the same thing myself. Maddening! And it's proportional to the number of BP events being generated so the more user activity you have, the more it occurs. Details in the LearnDash support site here.

I used the following code to fix:

// Fix for LearnDash causing 404s on BuddyPress activity (updates, messages)
add_filter( "learndash_flush_rewrite_rules", function( $flush, $post_options ) {
return true;
}, 4, 2 );
| improve this answer | |
  • Wow, thanks, this is super helpful! I don't know how I missed that FAQ in my previous research. (I wonder if it's new?) It's been a few months now since I pored over the WP core code for rewrite_rules stuff-- do you know why LearnDash specifically is choking on this and other custom post plugins are not? – buzzo Apr 20 '16 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.