How to set 301 redirect jump in php: set the status code [header( "HTTP/1.1 301 Moved Permanently" ); header("Location:your_dest_url")] before the jump.
The operating environment of this tutorial: Windows 7 system, PHP version 5.6, DELL G3 computer. This method is suitable for all brands of computers.
How to set 301 redirect jump in php:
Normal temporary jump in php usually uses:
header("Location:your_dest_url");
This kind of return The status code is 302
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");
Attachment: 30*The difference between 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 permanent transfer. (Permanently Moved),
302 redirect: 302 represents temporary transfer (Temporarily Moved),
When these two transfers are used What are the benefits or problems?
301 redirection is the best way to be friendly to search engines after the webpage changes its address. As long as it is not a temporary move, it is recommended to use 301 for redirection.
302 Redirect is a temporary transfer.
Use the above method to achieve php 301 redirection and permanent redirection of the URL.
For example:
<?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 video recommendations: PHP programming from entry to proficiency
The above is the detailed content of How to set up 301 redirect jump in php. For more information, please follow other related articles on the PHP Chinese website!