admin管理员组文章数量:1122846
I have a WP multisite on AWS running a nginx-based server. It has autoscaling enabled as well. For some reason, and for only some pages (mostly custom post types), after every deployment these CPT's will give 404s.
Then I need to manually go to the settings and go to permalinks and just resave the permalink structure to trigger rewrite rule flush.
Now, because we are deploying the site using codedeploy, I added a wpcli script that will do that for me
exec("~/bin/wp site list --json --field=url", $siteOuput, $return);
$siteList = json_decode($siteOuput[0], true);
foreach($siteList as $siteUrl) {
exec("~/bin/wp rewrite flush --url=$siteUrl", $permalinkOutput, $return);
}
This seemingly works (we have logging where it says that the permalink flush was successful for sites). However, this doesn't seem to be the case. When I go to a CPT, it will throw 404 and I need to manually go to the settings and resave permalinks.
The rewrite rules are set in the database so this is super confusing. Also, flushing permalinks from wpcli obviously is not working, so is there a difference between web and cli context here?
I did try to trigger a call to a rest route that had the logic for flushing permalinks, but that also didn't work (again here I suspected this wouldn't work from the rest API context).
Does anybody have any idea what could be the issue and how to fix this? The main issue is that when an autoscaling event happens, permalinks go kaput :S
I have a WP multisite on AWS running a nginx-based server. It has autoscaling enabled as well. For some reason, and for only some pages (mostly custom post types), after every deployment these CPT's will give 404s.
Then I need to manually go to the settings and go to permalinks and just resave the permalink structure to trigger rewrite rule flush.
Now, because we are deploying the site using codedeploy, I added a wpcli script that will do that for me
exec("~/bin/wp site list --json --field=url", $siteOuput, $return);
$siteList = json_decode($siteOuput[0], true);
foreach($siteList as $siteUrl) {
exec("~/bin/wp rewrite flush --url=$siteUrl", $permalinkOutput, $return);
}
This seemingly works (we have logging where it says that the permalink flush was successful for sites). However, this doesn't seem to be the case. When I go to a CPT, it will throw 404 and I need to manually go to the settings and resave permalinks.
The rewrite rules are set in the database so this is super confusing. Also, flushing permalinks from wpcli obviously is not working, so is there a difference between web and cli context here?
I did try to trigger a call to a rest route that had the logic for flushing permalinks, but that also didn't work (again here I suspected this wouldn't work from the rest API context).
Does anybody have any idea what could be the issue and how to fix this? The main issue is that when an autoscaling event happens, permalinks go kaput :S
Share Improve this question asked Sep 13, 2024 at 12:20 dingo_ddingo_d 1,9501 gold badge25 silver badges45 bronze badges 3- I wonder if it's making an nginx config change too, but then AFAIK WordPress only makes .htaccess edits out of the box. Do you have an nginx support plugin? Can you compare the config (or the filesystem in general) on a working instance against a broken one? I can't see why things wouldn't work from REST though, unless there's some extra admin-site-only logic somewhere. – Rup Commented Sep 16, 2024 at 9:34
- That said I don't think the permalink config varies by CPT type :-/ – Rup Commented Sep 16, 2024 at 9:34
- My hunch is that it's a caching fault. We do have wp redis as well, and maybe there could be a rewrite mismatch or something. So far it affects only CPTs – dingo_d Commented Sep 17, 2024 at 9:13
1 Answer
Reset to default 1So the problem was in the custom rest route which had the call to flush_rewrite_rules()
which (as far as I can see) resetted the permalinks to default somehow and messed up the permalink structure.
Once we removed all the calls to the custom route no 404 happened.
本文标签: custom post typesMultisite permalink issue
版权声明:本文标题:custom post types - Multisite permalink issue 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736289428a1928302.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论