301 and 302 are both HTTP status codes, and both represent that a certain URL has been transferred. The difference is: 301 represents Permanently Moved, and 302 represents Temporarily Moved.
301 redirect is the best way to be friendly to search engines after changing the address of a web page. As long as it is not a temporary move, it is recommended to use 301 for redirection. If we use 301 jump method for an address, If it is transferred, the search engine will bring the PageRank and other information of the old address to the new address, and at the same time completely discard the original old address in the search engine index library.
In PHP, the general statement to implement page jump is as follows:
php header('Location: http://www.wuwx.cn/');
When we used the tool to view this HTTP header, we found that it returned an HTTP 302 temporary redirect. Instead of the HTTP 301 permanent redirect we expect, pay attention to the first line in the picture below:
How should we implement HTTP 301 permanent redirect? It's actually very simple, just add one line of code:
php header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.wuwx.cn /');
When we look at the HTTP header of this page again, what it returns is the HTTP 301 permanent redirect we expected.