php returns a 301 redirect method: 1. Normal temporary jump method in php, the code is [header("Location:your_dest_url")]; 2. Set the status code before to implement php 301 jump, code is [HTTP/1.1 301 Moved].
php method to return a 301 redirect:
1. Normal temporary jump in php Use:
header("Location:your_dest_url");
The returned status code is 302
2. If you want to implement php 301
jump, you need to set the status code before:
header( "HTTP/1.1 301 Moved Permanently" ) ; header("Location:your_dest_url");
Note: The difference between 30* return status codes
301, 302 are both HTTP status codes, and both represent that a certain URL has been transferred. The difference is :
301 redirect: 301 represents Permanently Moved,
php 301 redirection and make a permanent redirection of
url.
<?php $the_host = $_SERVER['HTTP_HOST'];//取得当前域名 $request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';//判断地址后面是否有参数 header('HTTP/1.1 301 Moved Permanently');//发出301头部 header('Location: http://www.jbxue.com'.$request_uri);//跳转到目标
Related learning recommendations:
The above is the detailed content of How does php return a 301 redirect?. For more information, please follow other related articles on the PHP Chinese website!