A Beginners Guide to HTTP Response Codes
HTTP response codes help power the internet, from blogs, powerhouse publishers and powerful API’s, they all rely on HTTP response codes as a way for servers to communicate with each other, this includes client (i.e. you!) to server communications, too.
Almost everyone, from your grandmother to your little brother, has heard of a 404 error, check out our’s here. A 404 not found error is of course, when a page is not found by the server, but what’s happening here? When you’re extremely busy at work, looking up LOL catz for some important research and you come across a 404 error, what’s happened is you made a request via a URL, the server which stores the resource receives the request and in turn sends back a response, in this case, a 404 error status code.
Response Codes in Action
Before we go any further, lets look at some live examples, if we look at Dave Naylors blog, we can see a 200 response code is returned, go ahead and try it yourself:
Enter a URL with HTTP protocol, for example https://www.davidnaylor.co.uk/
This time try the following http://www.davidnaylor.co.uk/ notice it’s ‘http’ now rather than ‘https’. If you entered the URL you should have seen a 301 returned, the end URL will have been of course, with the https.
Common Response Codes You Should Know
The following are some of the common response codes you may come across, what they do, why they are important and when you should use them:
20X Response Codes
2XX response codes are known as “successful” status codes, an action has been received and returned successfully, for example this page you are reading now is returning a 200 status code. Yay!
- 200 OK – This is the most common 2XX response for successful HTTP requests. There’s not really much else to say at this stage, it’s all a bit boring really. However, there are some things you should learn to avoid, for example, don’t return a 200 response when you really mean to return a 404 as this may cause you some issues.
There are of course other 2XX responses but they are not seen quite as often, for example the 204 response code is commonly seen when deleting through an API; signalling the deletion was successful, from a database for example, but there was no content to return.
30X Response Codes
3XX status codes are known as redirect status codes; when a client is moved to a new location (i.e. from one URL to another), for example when a product has been discontinued and you are re-routed to the nearest category. 3XX response codes are where it gets a little more interesting, at least where the SEO/online marketing bod is concerned, here’s the breakdown:
- 301 Permanent Redirect – Ahh, the 301; a developers nightmare or so it would seem. 301 response codes signal to the client that a redirect is taking place, specifically, a permanent redirect, as in the redirect is unlikely to change anytime soon. This is significant, as search engines such as Google will treat a permanent redirect differently to a temporary redirect (up next), at least in the short term.
- 302 Temporary Redirect – As you’ll have guessed, a 302 temporary redirect is the same as a 301, only “temporary”, generally speaking these should be avoided for URL migrations and only used when the redirection is truly temporary, during server upgrades or maintenance, for example.The main difference is rather than the end location being indexed, the original location will be indexed – if these are left for an extended period they will be treated as a 301 redirect.
40X Response Codes
4XX response codes are known as client errors, these are status codes where a client shouldn’t have access or have accessed the URL in a certain way. Add https://www.davidnaylor.co.uk/oops to the little tool above and you’ll see the code returned. Now, let’s take a look at some of the common response codes you’ll come across:
- 403 Forbidden – Grrr. I have a personal hate for this one, but that’s another story. The 403 is to indicate the resource does exist but you don’t have permission to access it.
- 404 Not Found – This bad boy doesn’t need any introduction as we all know it but essentially it says, ‘Sorry, Boss! I can’t find what you’re looking for.’. People tend to get up in arms about this one – a few things for you to keep in mind:
- Create a friendly 404 page for your website users, free from any erroneous code, this is the one they are most likely to see.
- Ensure you return an actual 404 response code and not a 200. Otherwise your 404 page will likely get indexed by ‘The Google’.
- If redirecting these URLs (particularly if you have some sweet, sweet, links going to them), ensure you do it to where it makes sense to the user, don’t just redirect to the homepage
- Remember, 404 are a natural part of the decaying web – so chill.
- 410 Gone. Sadly, this little guy doesn’t get the attention it deserves, due to the 404 hogging the lime light. If you have permanently removed a resource you should return a 410 – The reason for this is a 410 is a fairly deliberate response code and if Google sees one, they will drop your page from the index (the same will happen with a 404 but it will take a little more time). Use this if you have a bunch of random URLs which hold no link equity, just to permanently banish them to the index graveyard.
50X Response Codes
5XX status codes are known as server errors, this is where the server has failed to deliver a valid request, this could be an error in the code for the route URL you are trying to access. I’ve listed here, arguably the 2 most common you’ll encounter.
- 500 Internal Server Error – This one is fairly common and it’s telling us there’s an issue server side, to diagnose this, we’d be heading straight for the server error logs as somethings gone Pete Tong – often from broken code ;).
- 503 Service Unavailable – Lastly, this is a secret dream of those in social media or marketing, as it’s caused by the server being overwhelmed, hopefully due to so many people trying to access the site! (Other times, it’s due to the server just having a hiccup 🙁
So that’s it! Hopefully you’ve found this crash course useful. Next time we’ll cover HTTP Request Methods. Follow us on Twitter to keep up to date. @Bronco