Reputation: 209
As Google Bot is visiting one of our websites with wrong URLs, I constantly get Server errors bugging me as Administrator (The reason is that I accidentially submitted a wrong sitemap 3 months ago. Yes, I have resubmitted, deleted, resubmitted several times but it's still visiting).
I now learned in the Google Forum that using a 410 response will make the goggle bot stop visiting.
Does anyone have an idea how to send a 410 response from Symfony2? If that won't work, I would also be fine with a plain PHP-solution.
Thanks a lot for any help.
Upvotes: 3
Views: 2600
Reputation: 1
I use this
$response = new Response();
$response->setStatusCode(410);
return $this->render('twig_template_uri', ['key'=> $value, ...], $response);
I am using this in a controller when the data exists but "isActive = false" for instance
Upvotes: 0
Reputation: 7606
That's basically the same as the previous answer, but using the a Twig 404 template (you must create) and a one liner:
use Symfony\Component\HttpFoundation\Response;
...
return new Response($this->renderView('TwigBundle:Exception:error404.html.twig'), Response::HTTP_GONE);
Upvotes: 0
Reputation: 209
I have tried this, seems to work. Will update once I learn whether it has a long-term effect
$response = new Response();
$response->headers->set('Content-Type', 'text/html');
$response->setStatusCode(410);
return $response;}
Upvotes: 3