Home >Backend Development >PHP Tutorial >php 301 redirect code_PHP tutorial
The best way to be friendly to search engines after changing the address of a webpage is to do a 301 redirect. If it is not to temporarily transfer one or some web pages, we all think it is more appropriate to do a 301 redirect.
The best way to be friendly to search engines after changing the address of a webpage is to do a 301 redirect. If it is not to temporarily transfer one or some web pages, we all think it is more appropriate to do a 301 redirect.
The following 301 redirect code is commonly used in PHP tutorials
header( "http/1.1 301 moved permanently" ) ;
header( "location: http://www.bKjia.c0m/" );
?>
301 redirect is a permanent redirect. When a user or a search engine sends a browsing request to our website, the website server will return an http data stream. The data stream header information (header) contains some kind of status code. 301 is a status code that indicates that this webpage has been permanently transferred to another address
Notes, about header function
header(string,replace,http_response_code)
The header() function sends raw http headers to the client.
It is important to realize that the header() function must be called before any actual output is sent (in PHP 4 and above, you can use output caching to solve this problem):