(Edit: Like one of the links below mentioned, it may have to do with the order in which the Matching Rule is called, the more engagement/traffic/activity a BP page gets, the more the rewrite rule is called on other pages, if there's something you can give me that keeps the original order for nonbuddypress pages, or removes the rewrite rule all together for nonbuddypress pages, that'll solve the problem I believe)
I’m currently running Buddypress with Woocommerce activated (Dokan as well.)
From time to time, much more when there’s heavier traffic, there will be random 404 errors on different parts of my website. I heard it has something to do with flush rewrite rules or something.
I’m not too good at these kinds of things, I was wondering if anyone heard of something similar happening. I read that it happens when people also use LearnDash with Buddypress, and I saw a specific fix to be put in functions.php for that, I was wondering if something can be applied to my situation.
Here’s are just a few questions that are similar (this is a problem a lot of people have been having for years, almost a decade of people asking):
https://buddypress.org/support/topic/buddypress-iis-and-randomreoccurring-404-errors/
https://buddypress.org/support/topic/getting-404-after-visiting-activity-stream-in-buddypress/
--
I uploaded a query monitor and found that on pages that get those 404 errors, there’s a different “Matched Rule” when the page is requested. When it’s not working it’s [^/]+)(?:/([0-9]+))?/?$
, when it is working it’s (.?.+?) (?:/([0-9]+))?/?$
I tried implementing the code in the below link, replacing my failed matched rule with theirs in the code, but I got critical errors. I’m wondering if the code is correct in my instance, and I added it to the class-wp file right after $rewrite = $wp_rewrite->wp_rewrite_rules(); (I don’t know what he means by “in the parse function request”), so I’m wondering if the place I placed it is correct as well:
if(isset($rewrite['([^/]+)(?:/([0-9]+))?/?$']))
{
$temp = $rewrite[^/]+)(?:/([0-9]+))?/?$'];
unset($rewrite['([^/]+)(?:/([0-9]+))?/?$']);
$rewrite['([^/]+)(?:/([0-9]+))?/?$'] = $temp;
}
https://buddypress.org/support/topic/getting-404-after-visiting-activity-stream-in-buddypress/
--
If no one knows what to do about this, is there any way at all to prevent Buddypress Rewrite Rules on Non-Buddypress pages/posts? Like some type of functions.php code?
(Related: https://core.trac.wordpress.org/ticket/48223, how can I implement this? This may also solve the issue.)