This is an article on how to perform a permanent redirect with PHP.
By default, the header function in PHP sends a 302 redirect code. This is problematic, as the 302 code tells browsers and web crawlers that the redirect is temporary. i.e. That the resource has been temporarily moved.
In many cases, you will want to provide a 301 redirect code, as the 301 code tells browsers and web crawlers that the redirect is permanent. i.e. The resource in question has been moved to another location.
If you look at the manual page for the header function, you will see that the function accepts three parameters (most people only use one). The third one is:
http_response_code: Forces the HTTP response code to the specified value. Note that this parameter only has an effect if the string is not empty.
Basically, this third parameter allows us to provide the header function with the HTTP status code that we want to use. In this case, we will be specifying a 301 HTTP status code.
The code above performs a permanent redirect to a fictional file name called mypage.php.
0 comments:
Post a Comment