The 410 Gone
status code is a part of the Hypertext Transfer Protocol (HTTP) status codes. It indicates that the requested resource is no longer available on the server and that no forwarding address is known. This condition is expected to be permanent. Clients receiving a 410 Gone
response should not request the resource again in the future.
When to Use 410 Gone
The 410 Gone
status code should be used when a resource has been intentionally removed and the server wishes to convey that the resource is not coming back. This is different from the 404 Not Found
status code, which indicates that the server could not find the requested resource but does not imply that it has been permanently removed. A 410 Gone
response should be used when the server wants to make it clear that the resource is gone for good and clients should not expect it to reappear.
Example
Request
GET /old-resource HTTP/1.1
Host: example.com
Response
HTTP/1.1 410 Gone
Content-Type: text/html; charset=utf-8
Content-Length: 98
Connection: close
<!DOCTYPE html>
<html>
<head>
<title>410 Gone</title>
</head>
<body>
<h1>410 Gone</h1>
<p>The requested resource is no longer available.</p>
</body>
</html>
In this example, the client has requested a resource that has been permanently removed from the server. The server responds with a 410 Gone
status code and a simple HTML message explaining that the resource is no longer available.
How to Implement 410 Gone on the Server
To implement the 410 Gone
status code on the server, follow these steps:
- Identify the resources that have been permanently removed and should return a
410 Gone
status code. - Configure the server to return a
410 Gone
status code and an appropriate response body for the identified resources. The response body can be an HTML message, a JSON object, or any other format that is suitable for your application. - Ensure that the server does not return a
410 Gone
status code for resources that have not been permanently removed or for resources that may become available again in the future. In such cases, consider using other status codes like404 Not Found
or307 Temporary Redirect
.
Handling 410 Gone in Clients
When a client receives a 410 Gone
status code, it should:
- Update any internal references or caches to remove the resource, as it is no longer available.
- Inform the user or the application that the resource has been permanently removed and will not be available in the future.
- Avoid requesting the resource again, as the server has indicated that it is gone for good.
Summary
In summary, the 410 Gone
status code is used to indicate that a requested resource has been permanently removed from the server and will not be available again. It is different from the 404 Not Found
status code, which does not imply permanence.
When implementing a 410 Gone
response on the server, ensure that it is only used for resources that are truly gone and will not return. Clients receiving a 410 Gone
response should update their references, inform users, and avoid requesting the resource again in the future.