.htaccess redirect all pages to new domain

前端 未结 18 2426
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 14:47

Which redirect rule would I use to redirect all pages under olddomain.example to be redirected to newdomain.example?

The site has a totally

18条回答
  •  -上瘾入骨i
    2020-11-22 15:24

    My solution as SymLinks did not work on my server so I used an If in my PHP.

    function curPageURL() {
        $pageURL = 'http';
        if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
        $pageURL .= "://";
        if ($_SERVER["SERVER_PORT"] != "80") {
            $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
        } else {
            $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
        }
        return $pageURL;
    }
    $redirect = str_replace("www.", "", curPageURL());
    $remove_http_root    = str_replace('http://', '', $redirect);
    $split_url_array     = explode('/', $remove_http_root );
    
    
    if($split_url_array[0] == "olddomain.com"){
        header("Location: http://www.newdomain.com/$split_url_array[1]");
        die();
    }
    

提交回复
热议问题