410 "Gone" with PHP
Posted September 3rd, 2009 in 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.
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.
- Setting 503 Service Temporarily Unavailable headers with Apache .htaccess (Sunday, March 14th 2010)
- 404 Page not found with PHP (Wednesday, October 29th 2008)
- 303 redirect with PHP (Thursday, July 31st 2008)
- 301 redirect with PHP (Saturday, March 15th 2008)