Server Response Codes - Beginner's Guide
Server response codes may seem like errors at first glance. They are usually obvious for every request we send to the server. However, on closer inspection, server response codes are also encountered when the website is operating normally.
Let me demonstrate this with a short metaphor.
Every time you visit a web page, there is a bureaucratic exchange of information between your browser and a remote server.
Your web browser (called the client) initiates this exchange by making a request to the server for the page code, images, and other information.
The server is always idle and returns various messages.
Example: "I got a request, here's what you can expect in the next few seconds."
Such messages containing server response codes are useful both for waiting clients and for optimizing their work.
Server Response Codes - Breakdown
The first digit of a code always indicates its total meaning, so you can quickly predict what they mean even if you don't know their details.
Here are the server response codes broken down:
2xx – Successful
The purpose of the returned 2xx code is to tell the client that everything has been read correctly and the page will be rendered as it is on server.
3xx - Redirection
These often misunderstood server response codes help update stale client requests.
4xx – Client Error
The client request was not made on the browser side. The most common response in this regard is an invalid link or a request for non-existent data on the server.
5xx – Server Error
The client request was not made on the server side. Repair and diagnostics usually require the intervention of a webmaster or just a knowledgeable person.
Server response codes - status 200
Server response with status 200 means "everything is fine, you will receive the requested information in a few seconds".
We get it every time the first page of the site loads correctly in the browser.
In this regard, can such a status be wrong?
A few months ago I wanted to buy a shirt. A certain brand ranked high in the rankings, so I immediately went to their website and found what I wanted. However, I had neither the ability nor the desire to press the "buy" button.
So I went back to the search results and followed every other link of this brand on the first page. With the same result.
I did some digging and checked. It turned out that their server was returning status 200 for every page that ever existed on their site. Because of this, old products were not removed from the search engine index and pushed out products that could actually be bought from the first page.
Server response codes - status 301
Status 301 - permanent redirect it is a message to the client that the information he is looking for is now in a different location.
Instead of downloading old information, the server updates the link, i.e. status 301 now leads to status 200, but in a new location.
If the client is a search engine, the old location will be replaced by the new one in the search engine index.
The 301 code is the perfect way to fix visitor requests that type in the wrong domain version.
Look at the example:
Our domain is mobiletry.com, but there are several versions:
- www.digiants .com/
301 server response codes can redirect from any given address to our main mobiletry.com domain. How to do it? I refer you to my previous post about the htaccess file and its usage.
The 301 code is also great for updating and moving content across a site or domain. The idea is that visitors who visit the old site are simply automatically redirected to the new one.
Status 301 becomes an error when the old site is still up to date. It will also be an error if the old location has no connection to the new one. Such a site will have an increased level of spam due to too many redirects from other sites.
Server response codes - status 302
302 - Found / Temporary Redirect, with this status you can confirm the client's request and say: "I found the information you are requesting, but this information will be available in the original location only over time".
The server starts parsing the new request, resulting in a return status of 200 in the new location. If the client is a search engine, the original location will still remain in the search engine's index.
302 server response codes cause a lot of problems, especially when the link should lead to a permanent and new location (301) or not found (404). Some webmasters mistakenly use chains of 302 and 301 redirects, which can lead to a significant increase in site loading time.
Server response codes - status 304
304 - No change, this is a redirect to a page that has already been cached by the client.
Then the server replies: "I received your request, but the information has not changed at all since the last request, so let's not waste time and use the page loaded last time."
This response code implies many logical requests between client and server. These two objects will interact as long as the cached information is up to date. We have the ability to specify when the cached information should be automatically updated. Again, we can use the .htaccess file for this:
ExpiresDefault "access plus 1 month"
ExpiresByType text/cache-manifest "access plus 0 seconds"
ExpiresByType text /html "access plus 0 seconds"
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType application/json "access plus 0 seconds"
ExpiresByType image/x- icon" access plus 1 week"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType text/x-component "access plus 1 month"
ExpiresByType font/truetype "access plus 1 month"
ExpiresB yType font/opentype" access plus 1 month"
ExpiresByType application/x-font-woff "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType application/vnd.ms- fontobject "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
What should we do in this case?
Refresh page? Close the site and open it again?
No. Generally speaking:
F5 on the keyboard or refresh with the mouse in the top bar can load the same web page we just saw. Even if its content is constantly changing.
Because the page is constantly loaded from the cache. Using Ctrl+F5 or Ctrl+R results in a full refresh i.e. clearing the cache. This ensures that we always have an up-to-date version of the site.
Server response codes - status 403
Server response with status 403 - Forbidden tells us that the server understands our request, but you do not have permission to view this information.
We get a 403 code when the client does not have proper access to the server. If someone makes an unauthorized attempt to break into the confidential structures of our site, this is a valid "error". Usually this status is given to search engine robots that try to index the site.
This happens through the robots.txt file where we deny access to our site, but it can also be the result of a bad web server configuration.
Server Response Codes - Status 404
The 404 - Not Found code reads: "I can't find the information you're asking for - it's likely that it never existed at all."
This is the most common mistake. The 404 code performs a very important function - it informs the client that what he requested was not found.
The 404 error is so common that many webmasters choose to customize it. We can set the 404 status to redirect clients to an internal search engine when it doesn't find what they're looking for.
How do we do it?
Once again, .htaccess comes to the rescue. Create your own unique codes and specify them as follows:
ErrorDocument 400 /error.php
ErrorDocument 401 /error.php
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php
The 404 code also indicates that search engine robots have found a dead end and should move to another location. This is extremely important when such a robot has limited time resources to devote to one website.
A 404 response is usually not a server error, but the result of an attempt to connect to outdated links or a simple typo in the URL. If your site has a lot of 404 errors, then you need to fix them immediately.
How to check your website for 404 errors?
To do this, you can use Screaming Frog or an online scanner like 404 Checker.
However, if you notice a lot of 404 errors from external links that cannot be updated, you should consider the 410 error.
Server Response Codes - Status 410
Status 410 - Missing (Deleted). This code is the server's way of telling the client that: "the information once existed, but it no longer exists."
Error 410 tells search engine bots and other websites that the requested information is only available for a while and everyone should remove the link to it.
Search engine robots in case of a 404 condition will still check it, but the 410 error is considered absolute. Because of their particular importance, webmasters prefer to avoid 410 errors by going back to 404 for all "not found" and "deleted".
Server response codes - status 503
Code 503 - Service Unavailable, this error requires more knowledge and time to fix. Status 503 is usually used if the server is overloaded and unable to respond to any request. Overload can be the result of a bad server configuration or a sudden increase in site traffic.
Please note that the 503 code also appears when buying a new domain and connecting it to the server. This is not caused by server overload, but by the lack of DNS propagation of the domain. Distribution can take anywhere from a few to 24 hours.
Server response codes - brief description
Server response codes are an important aspect of understanding the communication process. Knowing what a particular code means is a necessary skill in the age of ubiquitous Internet access, even if your role isn't to set up servers. We need to know where the error lies - on our side (client) or higher (server).