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
Add a comment  | 

1 Answer 1

Reset to default 1

There 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