When connecting to a Web page, the client (browser) sends a request to which the server processes the response, following the HTTP protocol handling code returns a 3 digit number.
This code is located on the first line of response, and is of the form:
HTTP /1.1 200 OK
. In php, the php function header () function from your script to adapt the code that the server returns to “force” the behavior of the client browser.
Quick overview of the most common codes.
200 OK
The code 200 is Nirvana. Everything went well, nothing to report. This is the default code.
301 Moved Permanently (aka Permanent Redirect)
The 301 or “permanent redirect” is widely used in SEO. He pointed to the client (browser or search engine crawler) that the requested resource (document, image, etc.) has been permanently moved.
Suppose I rename a file. As it is, search engines send users to pages that no longer exist (they will be an error 404 – document not found), and any inbound links enjoyed my pages are lost they also point vacuum.
With a permanent redirect, the motors being warned that the document has been moved, will update their indexes to send visitors directly to the correct URL. At the same time, the popularity brought by inbound links will be transferred to the new pages.
302 Moved Temporarily
Near the 301 redirect, the code 302 indicates that a document has been moved temporarily. Engines so as browsers will download the document at its new address, but the references will henceforth be the usual URL.
304 Not Modified
When they have a document in the cache, the browser sends a header If-Modified-Since that includes the date on which they have downloaded the document for the last time. If the document has not been changed, the server sends a response code 304, “unmodified”, that prevents the browser to re-download content that is current in its cache.
404 Not Found
The document to which the user tries to access has been moved, deleted, or the provided URL is simply incorrect. The server has nothing to return. You can configure Apache, at the Virtual Host (or. Htaccess) so that it refers, in this case, a particular document through the ErrorDocument 404 / file.html. If 404 is file.html will be served. This can (and should always) be used to send a custom 404 page, which includes at least a mini-site map, so that the user can continue his visit on the site.
500 Internal Server Error
The code 500 is the end of the world. The server failed to respond to the request, often due to a configuration error. So, first check your. Htaccess, just a trailing semicolon for the server so it does more.
Function header
The header () function in PHP to send a response code other than the usual 200. Because it modifies the headers, it must be used BEFORE a printable character is sent to the client. Otherwise, a warning “headers already sent” will be generated. Here, for example, the complete syntax for using the header () function to send a proper 301 redirect:
header(”HTTP/1.1 301 Moved Permanently”);
header(”Location: http://www.nouvelle-url.com/”);
exit;