Next.js Discord

Discord Forum

Can I use route handlers to return specific http response?

Answered
British Shorthair posted this in #help-forum
Open in Discord
British ShorthairOP
Hi, was wondering if you can use route handlers to return specific http responses. In my case I want to return a 410 status code, because I want to remove some pages from Google Search. Can't I just use a route handler to return that status code? If so, how?
Answered by Ray
sure you can do that
export function GET() {
  return new Response("", { status: 410 })
}
View full answer

3 Replies

Answer
btw if you want to return a custom status code for a particular page (page.tsx), you can't. you have to use e.g. noindex nofollow to prevent google from indexing the page