Status 410 "Gone" without middleware.
Unanswered
Long-legged ant posted this in #help-forum
Long-legged antOP
We released a new website and, as for SEO best practices, we need to:
- Redirect old pages which changed URL to new pages (which can be done in
- Send a 410 error for pages that no longer exist. Now we do it with a middleware that redirects to an
The problem is that the middleware is running for every requests (pages, assets), so that we have millions of function calls just to send a 410 HTTP status for a few pages.
@Multiflora rose seed chalcid suggested (via X) to use
How can we solve this problem without Next.js middleware, on Vercel?
For comparison, on Netlify you can specify also the HTTP Status in the
- Redirect old pages which changed URL to new pages (which can be done in
next.config)- Send a 410 error for pages that no longer exist. Now we do it with a middleware that redirects to an
error-410.tsx page sending the "410" HTTP StatusThe problem is that the middleware is running for every requests (pages, assets), so that we have millions of function calls just to send a 410 HTTP status for a few pages.
@Multiflora rose seed chalcid suggested (via X) to use
vercel.json (as we are hosting on Vercel), but there I can just see a "permanent" flag with no way to send a 410 HTTP status.How can we solve this problem without Next.js middleware, on Vercel?
For comparison, on Netlify you can specify also the HTTP Status in the
_redirects file.6 Replies
Multiflora rose seed chalcid
{
"redirects": [
{ "source": "/user", "destination": "/api/user", "statusCode": 410 }
]
}
"redirects": [
{ "source": "/user", "destination": "/api/user", "statusCode": 410 }
]
}
Long-legged antOP
Unfortunately this doesn't work: it doesn't build and I receive the error:
This is really bad, as for revamped websites, when you have a page that doesn't exist any more and has no direct mapping on the new site, the correct procedure is returning a 410.
Valid redirect statusCode values are 301, 302, 303, 307, 308. 410 is not accepted 😦This is really bad, as for revamped websites, when you have a page that doesn't exist any more and has no direct mapping on the new site, the correct procedure is returning a 410.
Original message was deleted
Long-legged antOP
Unfortunately the question isn't answered as the proposed solution doesn't work.
oh you edited the message
you can manually remove and mark answers btw
Multiflora rose seed chalcid
@Long-legged ant two other options, TIL that 410 status code with the location response header is out of spec.
- Do rewrites instead and call another route that returns 410 response with proper caching response headers so they can be cased on Vercel CDN as well as client side.
- Catch URLs with regex in middleware and return 410 response directly from the middleware.
- Do rewrites instead and call another route that returns 410 response with proper caching response headers so they can be cased on Vercel CDN as well as client side.
- Catch URLs with regex in middleware and return 410 response directly from the middleware.