I have read about many error code but I am little-bit confuse about Error code 404 and 410. I didn’t distinguish till now what these errors exactly pretend.
1 Answers
The 404
indicates, that the resource is not present at the given location, and it has probably never been (or server has no idea whether it has been).
The 410
, on the other hand, indicates that resource is not present anymore, but it used to be there in the past. It's a useful hint for some clients such as search engines, spiders etc., because they can remove this resource from their indexes.
From the HTTP 1.1 original RFC 2616 section 10.4.11:
The 410 response is primarily intended to assist the task of web maintenance by notifying the recipient that the resource is intentionally unavailable and that the server owners desire that remote links to that resource be removed. Such an event is common for limited-time, promotional services and for resources belonging to individuals no longer working at the server's site. It is not necessary to mark all permanently unavailable resources as "gone" or to keep the mark for any length of time -- that is left to the discretion of the server owner.
Also, about the difference between the two:
This condition [the 410] is expected to be considered permanent. Clients with link editing capabilities SHOULD delete references to the Request-URI after user approval. If the server does not know, or has no facility to determine, whether or not the condition is permanent, the status code 404 (Not Found) SHOULD be used instead.
It has been later rephrased in RFC 7231 section 6.5.4, but the meaning remains the same:
A 404 status code does not indicate whether this lack of representation is temporary or permanent; the 410 (Gone) status code is preferred over 404 if the origin server knows, presumably through some configurable means, that the condition is likely to be permanent.
-
1It deeply, deeply annoys me that virtually every rotten link points to a 404, not to a 410. Lazy backend devs. – DavidsKanal Aug 28 '19 at 23:10
-
3@DavidsKanal Seems to be right to me though. New links might match some old links by coincidence, so generally speaking it's more right to use 404 – Jimmy T. Feb 23 '21 at 21:59
-
@JimmyT. except if you know for a fact that no resource will ever be available on that link, which is the case with expired resources, that are still available in the database but the client is not supposed to access it anymore. – Szabolcs May 13 '22 at 11:45
-
@Szabolcs if the underlying software changes or the database gets reorganized you can't be sure about that – Jimmy T. May 18 '22 at 10:36
-
1Not necessarily lazy backend devs, @DavidsKanal. Speaking as a .net dev, I would have to go out of my way in the code we usually write for accessing rows to generate a distinction between 404 and 410. Consider soft deletes. You know the row is permanently gone, but the defacto query engine (EF) will not easily let you distinguish between a row which doesn't exist vs one which has merely been soft deleted without having to write the entire query yourself. Even that will be inefficient in terms of performance. – Tanveer Badar Jan 11 '23 at 13:27
-
Yeah I see that now. Dunno why my comment from 3 years ago sounds so needlessly pissy. I mean it still annoys me but blaming devs for being lazy was not the right response – DavidsKanal Jan 12 '23 at 14:04