Create a new 301.php page, and reference the 301.php page in the program entry file index.php
The content of 301.php is as follows, for reference only:
$the_host = $_SERVER['HTTP_HOST'];//Get the current domain name
$the_url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';//Judge the back part of the address
$the_url = strtolower($the_url);//Convert English letters to lowercase
if($the_url=="/index.php")//Judge whether Not the homepage
{
$the_url="";//If it is the homepage, the value is empty
}
if($the_host !== 'www.baidu.com')//If the domain name If it is not a URL with www, then perform the following 301 jump
{
header('HTTP/1.1 301 Moved Permanently');//Issue a 301 header
header('Location:http://www .baidu.com'.$the_url);//Jump to the URL with www
}
?>