Redirect only WordPress homepage with a 301 redirect

后端 未结 8 598
天命终不由人
天命终不由人 2021-01-14 21:53

I have a blog, lets say example.com and another blog installed in example.com/np which is not multisite but a different WordPress installation.

相关标签:
8条回答
  • 2021-01-14 22:18

    You can use is_home() or is_front_page() function to redirect your home page.

    0 讨论(0)
  • 2021-01-14 22:21

    You can use a Wordpress function to detect if you're on the home page:

    is_home

    http://codex.wordpress.org/Function_Reference/is_home

    <?php
    if ( is_home() ) {
        // This is a homepage - 301 Redirect
        header("HTTP/1.1 301 Moved Permanently"); 
        header("Location: http://www.example.com/np");
        exit;
    } else {
        // This is not a homepage
    }
    ?>
    
    0 讨论(0)
提交回复
热议问题