The implementation method of 301 redirection in PHP is very simple. We simply use the header to send the 301 status code, and then use the header to jump. The effect is the same as that of apache, iis, and nginx.
1: This method is more recommended because it can transfer all the original URLs of www.bKjia.c0m to the new address of bKjia.c0m
代码如下 | 复制代码 |
$the_host = $_SERVER['HTTP_HOST']; $request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; if($the_host == 'www.bKjia.c0m') { header('HTTP/1.1 301 Moved Permanently'); header('Location: http://bKjia.c0m'.$request_uri);// } ?> |
Two: Single page multi-site Php301 redirect code, www.bKjia.c0m and bKjia.c0m will 301 go to index.php, www.bKjia.c0m will 301 go to bKjia.c0m, otherwise it will go to the error page
The code is as follows | Copy code | ||||
{ header("HTTP/1.1 301 Moved Permanently"); Header("Location: /index.php"); } elseif($HTTP_HOST=="www.bKjia.c0m") { header("HTTP/1.1 301 Moved Permanently"); Header("Location: http://bKjia.c0m"); } else { Header("Location: /404.htm"); } ?> |
附上其它跳转办法
代码如下
|
复制代码
|
header('Content-type: text/javascript');
//Text (Plain) header('Content-type: text/plain');