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.