I have several urls with "/tag/" string; some of them have content and some of them don't, so they return 404.
How can I force them to return a 410 only for those that have no content?
I need a filter: has "/tag/" in URL and returns 404 -> redirect to 410.
I tried in theme_preprocess_html(&$variables) like this:
if ($pattern2){ //it has "/tag/" string
$status = \Drupal::requestStack()->getCurrentRequest()->attributes->get('exception');
if ($status && $status->getStatusCode() == 404){
$response = new Response();
$response->setStatusCode(410);
return $response;
}
}
It filters is working but nothing it's not redirecting to 410.
Thank you for your help!!