Home > Backend Development > PHP Tutorial > PHP implements 301 redirect code_PHP tutorial

PHP implements 301 redirect code_PHP tutorial

WBOY
Release: 2016-07-13 10:32:30
Original
1147 people have browsed it

301 redirect definition
301 redirect (or 301 redirect, 301 jump) is a type of status code in the header information (header) in the HTTP data stream returned by the server when a user or search engine sends a browsing request to the website server, indicating that this web page Permanent transfer to another address.
Other common status codes include, 200 means everything is normal, 404 web page not found, 302 temporary redirect, etc.
How to redirect a website
URL redirection methods mainly include: 301 redirection, 302 redirection, JavaScript redirection, PHP/ASP/CGI redirection, META REFRESH web page META refresh, etc. 302 redirects may have URL canonicalization issues. Other methods are commonly used cheating techniques. Of course, this does not mean that they cannot be used legitimately. There is nothing wrong with the methods themselves, but they are used by cheaters so much that search engines are very sensitive to these suspicious turns. Why take the risk?
The necessity of 301 diversion
When web page A uses a 301 redirect to redirect to web page B, the search engine can be sure that web page A has permanently changed its location, or actually no longer exists, and the search engine will treat web page B as the only valid target. The advantage is,
First, there is no URL normalization problem
Second, and very important, the PR page level of web page A will be transferred to web page B
Third, inclusion will not be lost due to domain name changes.
Realize
CODE:
$url=""];
header("HTTP/1.1 301 Moved Permanently");
header ("Location:$url");
?>
As shown in the php code above. This function can be realized. Where should the above code be placed? Let’s take Discuz6.0 as an example
index.php
archiver/index.php
forumdisplay.php
viewthread.php
space.php
tag.php
blog.php
Find the above files in the original old domain name and add the above code. It would be nice to update.
Test
It’s easy. If you want to test, just use curl, a small software.
#curl -I
HTTP/1.0 301 Moved Permanently
Date: Tue, 06 May 2008 06:27:39 GMT
Server: apache
Location:

If you see the HTTP/1.0 301 Moved Permanently above, it means it is OK. Next time you click on the relevant link, it will automatically redirect to the new link, and the search engine will automatically update to the new link

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/755626.htmlTechArticle301 redirect definition 301 redirect (or 301 redirect, 301 jump) is when a user or search engine redirects to a website When the server issues a browsing request, the header information (header) in the HTTP data stream returned by the server...
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