admin管理员组文章数量:1327987
I am using this code so that when the user visits the old permalink, he gets redirected to the new one.
add_action( 'template_redirect', 'redirect_to_external_url' );
function redirect_to_external_url() {
if ( is_page( '/' ) ) {
wp_redirect( '/', 301 );
exit;
}
}
However, this doesn't seem to work. I am also using Nginx. Any help would be much appreciated.
I am using this code so that when the user visits the old permalink, he gets redirected to the new one.
add_action( 'template_redirect', 'redirect_to_external_url' );
function redirect_to_external_url() {
if ( is_page( 'https://www.domain/brands/haute-couture/' ) ) {
wp_redirect( 'https://www.domain/brands/fashion/', 301 );
exit;
}
}
However, this doesn't seem to work. I am also using Nginx. Any help would be much appreciated.
Share Improve this question asked Jan 3, 2019 at 19:16 JoaMikaJoaMika 6986 gold badges27 silver badges58 bronze badges 1- Thank you very much for the question. I needed to redirect all posts of my wordpress site into a new NUXT frontend website. Pasted into the custom plugin I made, and it just works! – Imtiaz Commented Aug 14, 2020 at 17:45
1 Answer
Reset to default 1There is nothing wrong with wp_redirect
part of your code...
But... is_page
function can’t be used with URL address... You should pass “Page ID, title, slug, or array of such” as stated in documentation.
本文标签: Php function 301 redirect
版权声明:本文标题:Php function 301 redirect 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742248788a2440358.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论