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 quick metaphor.
Every time you visit a web page, there is a bureaucratic exchange of information between your browser and the 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've received a request, here's what you can expect in the next few seconds".
Such messages containing server response codes are useful both for pending ients, and to optimize their work.
Server response codes - breakdown
The first digit of a code always indicates its general meaning, so you can quickly predict what they mean even if you don't know the details.
Here are the server response codes broken down:
2xx – Successful
Goal return code 2xx - tell the client that everything was read correctly and the page will be displayed as it is on the server.
3xx – Redirection
These are often wrong Clearly understood server response codes help update stale client requests.
4xx – Client Error
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 ( 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 this 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 was neither able nor willing to click the buy button.
So I went back to the results search and clicked on every other link of that brand on the first page. With the same result.
I did some digging and checking. 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 - redirect is permanent, i.e. this is a message to the client that the information they are looking for is now located elsewhere.
Instead of loading 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.
Code 301 is the perfect way to fix queries from visitors who type the wrong domain version.
Look at the example:
Our domain is mobiletry.com, but there are several versions of it:
Codes about 301 server responses can be redirected 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.
Response codes server - status 302
302 - Found /Temporary Redirect, with this status you can confirm the client request and say : "I found the information you are asking for, but this information will not be available in the original location until some time later."
The server starts parsing the new request, resulting in a 200 return status 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 many 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 load time.
Server response codes - status 304
304 - No change, this is a redirect to a page that has already been cached client.
The server then 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 the response code implies many logical requests between the client and the 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"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType application/x-font-woff "access plus 1 month"
ExpiresByType image/svg+xml "a ccess plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
Header append Cache-Control "public"
This status is not seen as often as its 301 and 302 counterparts, but after reading "please clear the cache to see the changes", we can assume that this code is responsible.
What should we do in this case?
Reload page? Close the site and open it again?
No. Generally speaking:
F5 on keyboard or mouse refresh in the top bar can load the same webpage that we just saw. Even if its content is constantly changing.
Because the page is constantly being 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 don't 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 are denying access to our site, but this can also be the result of a bad web server configuration.
Codes server response - status 404
The 404 - Not Found code says: "I can't find the information you requested - it is 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 the internal search engine when it doesn't find what they're looking for.
How do we do it?
And once again .htaccess comes to the rescue. Create your own unique codes and specify them like this:
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.
Answer A 404 is usually not a server error, but the result of trying 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 site for presence 404 errors?
You can use Screaming Frog or an online scanner like 404 Checker for this.
However, if you notice a lot of 404 errors from external links that can't be updated, you should consider the 410 error.
Server response codes - status 410
Status 410 - Disappeared (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 engines and other websites that the requested information is only available for a limited time and everyone should remove the link to it.
Search engine robots will still check it in case of a 404 condition, but a 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 needs more knowledge and time to resolve. Status 503 is usually used if the server is overloaded and unable to respond to any request. The overload can be the result of a bad server configuration or a sudden increase in site traffic.
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. Propagation can take anywhere from a few to 24 hours.
Server response codes - short 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. You need to know where the error lies - on our side (client) or higher (server).