Throwing a legit 404 header from a SSG, NextJS, page that displays a 404 display?

Viewed 21

I am having real bad issues with bots. As such, because in NextJS SSG pages, dynamic/incremental, when I can't get the data I need, I returned (tried these).

Throw New Error

and

notFound: true,

ala

  if (someCondition) {
    return {
      notFound: true,
    }
  }

or

  if (someCondition) {
    throw new Error(`some error`)
  }

each of those DO return a 404 error page, BUT the response in the header is a 200. Thus, google sees that as a legit response, and KEEPS caching and crawling that page. I have thousands of these pages now, I can't enter each in one by one...... into googles tool.

Is there a way to have Vercel legitemately return a status 404 on these 404 display pages, instead of a status 200?

Because the page is dynamic, I read some data from the url, if I am able to get the data I need via apis (from params in url) cool, show page. BUT, when I can't, I do NOT want it to be a legit page... its suppose to be a status 404... how?

Perhaps another option is to dynamically, not sure how, add a "noindex" to the meta tag, but that seems haphazard.

Update: Adding this to my 404 page didn't work. The meta tags didn't update.

  <NextSeo title={`Error Page ${code}`} noindex={true} nofollow={true} />
0 Answers
Related