Home > Backend Development > PHP Tutorial > Implementing HTTP 301 Permanent Redirect with PHP_PHP Tutorial

Implementing HTTP 301 Permanent Redirect with PHP_PHP Tutorial

WBOY
Release: 2016-07-21 14:57:00
Original
1017 people have browsed it

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364084.htmlTechArticle301, 302 are both HTTP status codes, and both represent that a certain URL has been transferred. The difference is that : 301 represents Permanently Moved, 302 represents Temporary Move...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template