1

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?

4

1 回答 1

1

最好的方法是不删除内容而只取消发布它,如果您的节点状态 = 0,您可以添加标题 410,否则您可以使用 hook_boot 来实现类似的东西,但这不是完美的方法:

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;
        }
    }
}
于 2018-02-28T13:29:01.223 回答