Reputation: 21
We have a drupal based job board on which the jobs listings are updated via automatic imports every few days and some jobs are deleted in the process.
google search console shows errors for the indexed pages that pages - because the URLs return 404 status.
I think the solution should be a returning a 410 code on the URLs of the deleted content.
Does anyone have a clue how to achieve this?
Upvotes: 1
Views: 1200
Reputation: 2173
the best way is not to delete content but only unpublish it , you can add header 410 if your node status = 0 otherwise You can use an hook_boot to achieve something similar but it's not the perfect way :
function MYMODULENAME_boot(){
if(preg_match('#^\/node\/[0-9]+$#', request_uri())) {
list(, $nid) = explode('/', trim(request_uri(),'/'));
$registered = db_query('SELECT nid FROM node where nid = :nid', array(':nid' => $nid))->fetchField();
if(empty($registered) || !is_numeric($registered)){
drupal_add_http_header('Status', '410 Gone');
exit;
}
}
}
Upvotes: 1