Home > Article > CMS Tutorial > How to add 301 of PHPCMS?
First open the "index.php" file in the root directory; then determine if "$_SERVER['HTTP_HOST']" is equal to the set domain name and use the function "header()" to The HTTP status code is set to 301; finally jump to the specified URL.
Code sample
$the_host = $_SERVER['HTTP_HOST'];//取得当前域名 if(strtolower($the_host) != 'test.com')//把这里的域名换上你想要的 { $URIRedirect=$_SERVER['REQUEST_URI']; //获取域名后的参数 if(strtolower($URIRedirect)=="/index.php")//判断是参数为/index.php就显示为/ { $URIRedirect="/"; } header("HTTP/1.1 301 Moved Permanently");//发出301头部 header("Location: http://www.test.com" . $URIRedirect);//跳转到你希望的地址格式 exit(); }
Recommended tutorial: "PHPCMS Tutorial"
The above is the detailed content of How to add 301 of PHPCMS?. For more information, please follow other related articles on the PHP Chinese website!