Home > Backend Development > PHP Tutorial > 301 php 301 redirection implementation code

301 php 301 redirection implementation code

WBOY
Release: 2016-07-29 08:38:50
Original
974 people have browsed it

301 redirect definition
301 redirect (or 301 redirect, 301 jump) is a status code in the header information (header) in the HTTP data stream returned by the server when a user or search engine makes a browsing request to the website server. , indicating that this web page has been permanently moved to another address.
Other common status codes include, 200 means everything is normal, 404 web page not found, 302 temporary redirect, etc.
Methods for website redirection
Website 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 redirection
When webpage A uses 301 redirection to redirect to webpage B, the search engine can be sure that webpage A has permanently changed its position, or actually does not exist, and the search engine will regard webpage B as the only valid one. Target. The advantage is,
First, there is no URL standardization problem
Second, and also 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 change.
Achieved

Copy Code The code is as follows:


$url="http://www.php-oa.com".$_SERVER["REQUEST_URI"];
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? We 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, Add the above code. It would be nice to update.
Testing
It’s easy. If you want to test, just use the curl software to check.
#curl -I http://www.bbbb.com/sssss.php
HTTP/1.0 301 Moved Permanently
Date: Tue, 06 May 2008 06:27:39 GMT
Server: apache
Location: http://www.jb51.net/sssss.php
If you see HTTP/1.0 301 Moved Permanently above, it means it’s OK. Just click related next time The link will automatically redirect to the new link, and the search engine will automatically update to the new link.

The above introduces the 301 php 301 redirection implementation code, including the 301 content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
301
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