Sona
Sona

Reputation: 103

WordPress Redirection issue

I want to redirect aboutus page to its about us page and rest url will have to redirect at home page i had tried this soltion but about is not redirecting to its about page

add_action( 'template_redirect', 'wpse_76802_goodbye_redirect' );

function wpse_76802_goodbye_redirect() {

    $url = $_SERVER["REQUEST_URI"];
    $isWebservice = strpos($url, 'webservice');
    $isebizzmaster = strpos($url, 'ebizzmaster');
    $isjanvadb = strpos($url, 'janvadb');
    $iswpadmin = strpos($url, 'wp-admin');
    $cu = strpos($url, 'contact-us');
    $au = strpos($url, 'about-us');
    $pp = strpos($url, 'privacy-policy');
    //$cuid=
    //$wp_content = explode("/", $url);
    //$content = $wp_content[sizeof($wp_content)-2];
    if($au)
    {
        wp_redirect( home_url( 'index.php?page_id=619' ), 301 );
        exit;
    }
    if ( $isWebservice !== false || ! is_page( 25935 ) || $isebizzmaster  || $isjanvadb || $iswpadmin ) {
        wp_redirect( home_url( 'index.php?page_id=25935' ), 301 );
        exit;
    }
}

Help will be appriciated

Upvotes: 3

Views: 62

Answers (1)

Ashish Patel
Ashish Patel

Reputation: 3614

Try Below Code...

add_action( 'template_redirect', 'wpse_76802_goodbye_redirect' );

function wpse_76802_goodbye_redirect() {

    $url = $_SERVER["REQUEST_URI"];
    $isWebservice = strpos($url, 'webservice');
    $isebizzmaster = strpos($url, 'ebizzmaster');
    $isjanvadb = strpos($url, 'janvadb');
    $iswpadmin = strpos($url, 'wp-admin');
    $cu = strpos($url, 'contact-us');
    $au = strpos($url, 'about-us');
    $pp = strpos($url, 'privacy-policy');
    //$cuid=
    //$wp_content = explode("/", $url);
    //$content = $wp_content[sizeof($wp_content)-2];
    if($au!== false)
    {
        wp_redirect( home_url( 'index.php?page_id=619' ), 301 );
        exit;
    }
    if ( $isWebservice !== false || ! is_page( 25935 ) || $isebizzmaster  || $isjanvadb || $iswpadmin ) {
        wp_redirect( home_url( 'index.php?page_id=25935' ), 301 );
        exit;
    }
}

Upvotes: 1

Related Questions