Home > Article > Backend Development > PHP code to implement 301 jump page example_PHP tutorial
301 jump is to tell the visitor that the page has reached a new page forever. To use 301 jump in PHP, we use the header() function to send the 301 status code to tell the browser, and then implement the page jump.
PHP pure code jump
The code is as follows | Copy code | ||||
|
代码如下 | 复制代码 |
header( "HTTP/1.1 301 Moved Permanently" ) ; |
If you want to implement 301 jump, you need to set the status code before
The code is as follows | Copy code |
代码如下 | 复制代码 |
$urlto='http://www.bKjia.c0m/'; |
header("Location:http://www.bKjia.c0m/");
?>
Simpler PHP jump 301 code
The code is as follows | Copy code |
$urlto='http://www.bKjia.c0m/'; header('Location: '.$urlto, TRUE, 301); ?> |
Possible problems
Warning: Cannot modify header information - headers already sent by Changing the file encoding to UTF-8 without BOM format can solve this problem. If there is still a problem, check whether a string variable is defined before the code and delete this variable and try again.
Attachment: The difference between 30* return status codes
301 and 302 are both HTTP status codes, and both represent that a certain URL has been transferred. The difference is:1.301 redirect: 301 represents Permanently Moved,
http://www.bkjia.com/PHPjc/633121.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/633121.htmlTechArticle301 jump is to tell the visitor that the page has reached a new page forever. Use 301 jump in php We use the header() function to send a 301 status code to tell the browser, and then implement the page jump...