Home  >  Article  >  Backend Development  >  header() 301 redirection implementation code_PHP tutorial

header() 301 redirection implementation code_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:02:291289browse

Let’s look at an example first,

header('location: http://www.111cn.cn/');

The above is a simple jump. How do we make a permanent redirection? as follows.


Grammar
header(string,replace,http_response_code) parameter description
string required. Specifies the header string to be sent.
replace optional. Indicates whether this header replaces the previous header, or adds a second header.

Default is true (replacement). false (allow multiple headers of the same type).

http_response_code Optional. Force the http response code to the specified value. (php tutorial 4 and above available)


Among others, http_response_code is the 301 code we want to write, as follows.


$url = "http://www.zhutiai.com";
header("http/1.1 301 moved permanently");
header("location: $url");
exit();

Note: From php 4.4 onwards, this function prevents multiple headers from being sent at once. This is a protection measure against header injection attacks.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445357.htmlTechArticleLet’s first look at an example, header(location: http://www.111cn.cn/); The above is A simple jump, how do we make a permanent redirection. as follows. Syntax header(string,replace,http_respo...
Statement:
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