Everything You Wanted To Know About HTTP Status Codes

Last updated December 5th, 2023 23:46

Each of us practically uses the internet on a daily basis and displays content on various devices that we are searching for. When you send a request to the server through your browser to display content, you usually receive an HTTP status code, which tells the browser how the request to the server was handled. HTTP status codes are part of the HTTP protocol, which defines communication between the client and the server. Some codes are seen as errors, while others are not seen at all (e.g., 200, 301…). So, let’s take a closer look at the codes you encounter most frequently. Everything you wanted to know about HTTP status codes can be found here. You’ll learn what each code is used for and what they typically mean, not only in the case of errors but also in desirable situations.

Everything You Wanted To Know About HTTP Status Codes

Vše, co jste chtěli vědět o HTTP stavových kódech

HTTP Status Code 200 – Success

You receive a 200 code in a situation where the HTTP request was successful. This means that the server has successfully received and processed the request. Its includes scenarios where the request for a web page is successful, and the server returns the expected page or its content. This code is not an error but a confirmation that everything went well. It represents the ideal state you expect when entering any domain into your browser.

HTTP Status Code 301 – Redirection (Moved Permanently)

You often encounter this code when there is a change in the URL structure or when content is moved to a different location on the web or the internet. This technique can be useful for maintaining good SEO (Search Engine Optimization), especially when migrating a website to a new domain. The 301 code indicates a permanent redirection of content to a new URL address. It informs the client (and search engines) that the old URL is no longer valid, and the new URL should be used instead. This helps you maintain consistency in web links and minimizes the loss of SEO ranking.

Search engines will understand that the content at a particular address is now located elsewhere. It’s also advisable to use 301 redirection when you want to avoid duplicate content. Such duplication can occur when both the www and non-www versions of your website are accessible simultaneously. The best practice is to use only one of these variations and redirect the other using a 301.

Example of 301 redirection in PHP code:

				
					<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://dommain.tld");
exit();
?>
				
			

HTTP Status Code 302 – Redirection (Found, Moved Temporarily)

HTTP status code 302, often referred to as “Found” or “Moved Temporarily,” is a crucial element of the HTTP protocol, signaling temporary redirection of web content to a different URL. This code is used when the server informs the client (typically a web browser) that the requested content has been temporarily moved to another address, and the client should make a new request to this new URL. Code 302 is a key tool for managing redirection correctly. When a web server returns this code, the client typically automatically initiates a new request to the specified address, allowing users to smoothly access content that has been temporarily relocated. This approach can be useful for updates or modifications to the URL structure of web pages.

Importantly, code 302 designates only a temporary redirection. This means that the original URL may, in the future, contain the desired content again. Therefore, clients should use the new URL only temporarily. This distinction as a temporary change is significant for preserving SEO rankings and maintaining valid links to web pages. In practice, web developers often use code 302 to address situations where websites have a temporary change in content or URL structure.

Example of redirection using 302 in PHP code:

				
					<?php
header("HTTP/1.1 302 Found");
header("Location: https://domain.tld");
exit();
?>
				
			

HTTP Status Code 401 – Unauthorized

Code 401 signifies that the user does not have permission to access the content. User authentication is required, typically through a username and password. In practice, you encounter this status code wherever you need to log in to view content. As an example, you may encounter this code when a website has a password-protected directory using a .htaccess file.

HTTP Status Code 403 – Forbidden

Code 403 indicates that you do not have permission to access specific content or a page. The error occurs due to server-side restrictions. In practice, you may encounter this code, for instance, when you enter incorrect login credentials, and the server refuses to provide the requested content. You can also encounter this code when the server denies you access, for example, due to GEO-IP blocking (if you are accessing the website from a country that is banned or blocked on the server).

HTTP Status Code 404 – Not Found

The 404 error is perhaps the most common error you’ll encounter on the internet (if we’re talking about visible errors). This code most frequently indicates that a web page was not found. It means the server couldn’t locate the requested page or file you are referring to. This can be due to an incorrect URL, deletion, moving the page, or even misconfigured rewrite rules for making “pretty” URLs. From an SEO perspective, this status code also plays a significant role. When creating websites, it’s good practice to have a custom 404 error page. This not only alerts the user to the problem but also helps search engines. It also offers a creative opportunity to guide users to other potentially interesting content on your website.

For more information on the 404 error, you can refer to this article:404 error page

HTTP Status Code 408 – Request Timeout

This code signals that the server did not receive a complete request from the client within a specified time limit. This can be caused by several factors, including a slow internet connection between the client and server, server busyness, or other factors preventing the timely delivery of the request.

  • Reasons for Occurrence: Code 408 appears when the client does not provide the server with a complete request, including all necessary information and data, within the designated time limit. This can occur if the client’s connection was too slow or if there were issues with data transmission.
  • Handling Code 408: The client should respond to code 408 by resending the request. Most web browsers do this automatically. If the issue with the time limit persists, it may be a sign of a problem with the client’s internet connection or an overloaded server.
  • Practical Use: Code 408 is often encountered in online applications where the speed of communication between the client and server is crucial. For example, when submitting a form on a website, a status code of 408 may occur if the data submission takes too long.

HTTP Status Code 409 – Conflict

The HTTP status code 409 is called “Conflict.” This code signals that the server couldn’t process the client’s request because there was a conflict with the server’s state. Conflicts typically arise when two or more clients perform operations that are in conflict with each other or overlap with resources on the server subject to versioning or constraints.

In simple terms, code 409 appears when the server detects a conflict between different client requests for the same resource or data object. This may involve attempts to update data that has been changed by another user in the meantime.

HTTP Status Code 500 – Internal Server Error

Error code 500 indicates an internal server error. This code typically informs the user that there has been an error on the server’s side, preventing the request from being processed. This can be caused by programming errors, database unavailability, or server overload. Users cannot resolve this error themselves and should contact the web server operator. Possible causes of this problem may include incorrect file permissions, issues in the source code, incorrect syntax in the .htaccess file, and many others.

HTTP Status Code 503 – Service Unavailable

Code 503 indicates that the service or server is temporarily unavailable. The reason can be maintenance, server overload, or other temporary issues.

HTTP Status Code 504 – Gateway Timeout

This code signals that the server, acting as a gateway, did not receive a response in time from another server or gateway it was communicating with. Status code 504 does not directly relate to the client’s request and the server but instead indicates a problem in communication between one server and another.

Everything You Wanted To Know About HTTP Status Codes

Conclusion

In this article, I’ve covered the status codes that are arguably the most common in standard communication between a client and a server. Why is it good to understand the meaning of these codes? The reason is that you will often encounter these codes during the final debugging of a website. When something isn’t working on a website, you can investigate issues, for example, through the web console, where you can see the precise communication happening between the client and the server in the network section. When troubleshooting, it’s highly beneficial to know the meaning and characteristics of these codes because they frequently provide excellent clues as to where to begin looking for problems.

The website is created with care for the included information. I strive to provide high-quality and useful content that helps or inspires others. If you are satisfied with my work and would like to support me, you can do so through simple options.

Byl pro Vás tento článek užitečný?

Klikni na počet hvězd pro hlasování.

Průměrné hodnocení. 0 / 5. Počet hlasování: 0

Zatím nehodnoceno! Buďte první

Jak užitečný vidíte tento článek.

Sledujte mě na sociálních médiích.

Je mi líto, že pro Vás nebyl článek užitečný.

Jak mohu vylepšit článek?

Řekněte mi, jak jej mohu zlepšit.

newsletter

Subscribe to the Newsletter

Stay informed! Join our newsletter subscription and be the first to receive the latest information directly to your email inbox. Follow updates, exclusive events, and inspiring content, all delivered straight to your email.

Odebírat
Upozornit na
guest
0 Komentáře/ů
Vložené zpětné vazby.
Zobrazit všechny komentáře.

Pokud mi chcete napsat rychlou zprávu, využije, prosím, níže uvedený
kontaktní formulář. Děkuji.

Další Kontaktní údaje