Page Rule to respond with specific HTTP response code

It would be extremely useful to be able to respond to a request for a certain URL with an HTTP 410 (Gone) code.

The use case here would be when certain urls that no longer exist on the origin server need to be removed from crawlers like googlebot etc.

An HTTP 410 response rule would be brilliant. A generic HTTP response code would be awesome too.

Thanks

1 Like

We have the same problem with ‘410 gone’ status.

Has Cloudflare a solution for this?

You could make a worker for this. Basically, replace your_test_condition with whatever in-URL pattern you want to 410.

addEventListener('fetch', event => {
  event.respondWith(fetchAndLog(event.request));
})

async function fetchAndLog(request) {
  if (/(your_test_condition)/g.test(request.url)) {
    return new Response("Page is gone.", {
      status: 410,
      statusText: "Gone"
    });
  }
  return fetch(request);
}
2 Likes

Apologies for bumping this but perhaps someone has some updated code for this

Im trying to 410 certain URLS, for example /category/new-stuff/mugs/fox

Little lost on this one, can someone clarify what I would enter in your_test_condition using OP’s example?