admin管理员组文章数量:1279050
Hello I have a problem where i have 404 on posts after changing url with php using this function
wp_update_post( array(
'ID' => $post_id,
'post_name' => $new_slug
));
This happens in cases like the example below
if original post link abc/how-to-example
if I change to abc/how-to-example-passwd <-- redirect will still work
and I change again to a new permalink for third time redirect will work only for original link and new link and changes made between those two will return 404
Is it possible to keep all changes and make them redirect to current post using php?
I noticed wp automatically keep a custom field for the original link only
Hello I have a problem where i have 404 on posts after changing url with php using this function
wp_update_post( array(
'ID' => $post_id,
'post_name' => $new_slug
));
This happens in cases like the example below
if original post link abc/how-to-example
if I change to abc/how-to-example-passwd <-- redirect will still work
and I change again to a new permalink for third time redirect will work only for original link and new link and changes made between those two will return 404
Is it possible to keep all changes and make them redirect to current post using php?
I noticed wp automatically keep a custom field for the original link only
- Why are you doing this? This appears to be a terrible idea. – vancoder Commented Oct 18, 2021 at 15:39
1 Answer
Reset to default 0You will need to add the following code in your htaccess
.
Redirect 301 <Old Url> <New Url>
Place old link of your post in place of <Old Url>
and new link in place of <New Url>
For reference view this link.
本文标签: php404 on old link after changing post url
版权声明:本文标题:php - 404 on old link after changing post url 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741263878a2368104.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论