Home / 410 “Gone” with PHP

410 “Gone” with PHP

If a resource has been removed from a website, will not be available again and no forwarding address is available then it should return a 410 "Gone" HTTP status. This post explores the 410 status compared with a 404 "Not Found" and 301 "Moved Permanently" and shows how to do a 410 with PHP.

410 Gone

In most cases, developers and webmasters let their webservers respond with a 404 Not Found response code after they have removed a file or webpage. There is nothing necessarily wrong with this but there are two alternatives; the first is to do a permanent redirect using a 301 status code to some other equivilent resource, and the second is to send a 410 Gone status code which indicates the resource has been taken away and this change is permanent.

In theory, sending a 410 status from a deleted web page should stop search engine spiders and other bots from continually requesting pages that no longer exist (for example I’ve seen Yahoo!’s Slurp bot continue to ask for 404 pages for several years after they were removed) but in practise they may well also ignore a 410. But at least it’s worth a try 🙂

410 Headers with PHP

Sending a 410 header with PHP is as simple as this:

header("HTTP/1.0 410 Gone");

It’s advisable to then also send some text or a regular HTML web page after the header so that the browser as something to display because many of them will simply show a blank page.

Something as simple as this is better than nothing:

<?php
header("HTTP/1.0 410 Gone");
?>
The requested page has been removed.

but you can include full HTML and therefore include your website’s template as part of the page returned.