Home > Backend Development > PHP Tutorial > PHP code to implement 301 jump page example_PHP tutorial

PHP code to implement 301 jump page example_PHP tutorial

WBOY
Release: 2016-07-13 10:44:13
Original
979 people have browsed it

301 jump is to tell the visitor that the page has reached a new page forever. To use 301 jump in PHP, we use the header() function to send the 301 status code to tell the browser, and then implement the page jump.

PHP pure code jump

The code is as follows Copy code
 代码如下 复制代码

header("Location:http://www.bKjia.c0m/");
?>

header("Location:http://www.bKjia.c0m/");

?>

But the status code returned is 302
 代码如下 复制代码

header( "HTTP/1.1 301 Moved Permanently" ) ;
header("Location:http://www.bKjia.c0m/");
?>

If you want to implement 301 jump, you need to set the status code before

The code is as follows Copy code
代码如下 复制代码

$urlto='http://www.bKjia.c0m/';
header('Location: '.$urlto, TRUE, 301);
?>

header( "HTTP/1.1 301 Moved Permanently" ) ;

header("Location:http://www.bKjia.c0m/");

?>

Simpler PHP jump 301 code

The code is as follows Copy code

$urlto='http://www.bKjia.c0m/';

header('Location: '.$urlto, TRUE, 301);

?>

Possible problems

Warning: Cannot modify header information - headers already sent by Changing the file encoding to UTF-8 without BOM format can solve this problem. If there is still a problem, check whether a string variable is defined before the code and delete this variable and try again.

Attachment: The difference between 30* return status codes

301 and 302 are both HTTP status codes, and both represent that a certain URL has been transferred. The difference is:

1.301 redirect: 301 represents Permanently Moved,

2.302 redirect: 302 represents Temporarily Moved, What are the benefits or problems when using these two transfers? 301 redirection is the best way to be friendly to SEO 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.
http://www.bkjia.com/PHPjc/633121.htmlwww.bkjia.com
truehttp: //www.bkjia.com/PHPjc/633121.htmlTechArticle301 jump is to tell the visitor that the page has reached a new page forever. Use 301 jump in php We use the header() function to send a 301 status code to tell the browser, and then implement the page jump...
Related labels:
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