So a single post request sometimes gets redirected to the home page? And re-saving permalinks settings resolves this? This indicates an issue with WP rewrite rules. If the problem eventually returns, requiring another permalinks settings save, it likely means your theme or one of your plugins is messing with rewrite rules.
You’ll want to narrow down which module is responsible. To do so efficiently, you’ll want to be able to consistently cause the problem to occur. For example, requesting a specific post always gets redirected? Switch to a default theme and deactivate all plugins. Revisit the permalinks settings. You likely don’t even need to save, just loading the screen causes rewrite rules to be regenerated. The redirect problem should no longer occur.
Restore your normal theme and plugins, one at a time, each time going to permalink settings and then testing for a redirect. When the problem recurs, the issue is with the last activated module. Take up the issue in that module’s dedicated support channel.
@bcworkz thanks for taking a look.
Unfortunately the issue occurs on all root posts and yeah, oddly enough, saving permalink settings is the solution.
Hmmm, we have a custom theme and don’t auto-upgrade plugins or install new ones often.
Although, 3 weeks prior to noticing the first instance of the issue our hosting company KH upgraded all sites on our server to php 8.1 (unsure of prior version). It’s happened 2x since then so it’s not a 1-off-issue.
Do you think this might have something to do with it?
—
I can’t seem to recreate it regardless of what I try. And if it does return, I can test going to the permalink settings page without saving.
But uninstalling all plugins and using a default theme isn’t feasible on the live site.
You can use the Health check & Troubleshooting plugin to help you debug the site without affecting other visitors. Only your view of the site is affected in troubleshooting mode.
If visiting permalinks settings without saving resolves the issue, then something is certainly messing with the rewrite rules. If not, something is messing with the permalink setting itself and not the rewrite rules.
The problem is, if you cannot induce the issue somehow, it’s going to take a long time to resolve this through trial and error of deactivating different modules. The troubleshooting mode might not even help in such a situation since it works by making a clone of your site to test with. It’s conceivable the problem could be induced on the production version without affecting the clone.
@bcworkz thanks for the suggestions. I suppose I can take a backup when this happens again and diagnose on local as well.
All of that makes sense.
I had considered auto-magically saving the permalink settings a few times per day but that’s definitely a bandaid and would impede on diagnosing.