Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom 404 page has status code 200 OK #7516

Closed
1 task
xriter opened this issue Jun 29, 2023 · 7 comments · Fixed by #7711
Closed
1 task

Custom 404 page has status code 200 OK #7516

xriter opened this issue Jun 29, 2023 · 7 comments · Fixed by #7711
Assignees
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)

Comments

@xriter
Copy link

xriter commented Jun 29, 2023

What version of astro are you using?

2.7.0

Are you using an SSR adapter? If so, which one?

Node

What package manager are you using?

npm

What operating system are you using?

Mac

What browser are you using?

Safari

Describe the Bug

I created a custom 404 page (following the docs: https://docs.astro.build/en/core-concepts/astro-pages/#custom-404-error-page).

But when hitting this page, the status code of the document is still 200 OK!?
404 Not Found is expected.

(Use the web inspector to see this.)

Note that the logs of Astro ARE logging 404 though. Is the status code of the page even set by Astro?

What's the expected result?

Status code 404

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-xjlmoy?file=src%2Fpages%2Findex.astro

Participation

  • I am willing to submit a pull request for this issue.
@xriter xriter changed the title Custom 404 page still has status code 200 OK iso 404. Custom 404 page has status code 200 OK Jul 11, 2023
@xriter
Copy link
Author

xriter commented Jul 11, 2023

Perhaps any updates on this topic? For SEO reasons, this is quite an annoying bug that I haven't been able to find an easy solution for...

@ematipico
Copy link
Member

Will look into it

@ematipico ematipico self-assigned this Jul 12, 2023
@ematipico
Copy link
Member

ematipico commented Jul 12, 2023

@xriter , The 200 status code is returned only in development, but I can see the 404 status code when building with the node adapter. Is your issue related only to the development mode?

@ematipico ematipico added the needs response Issue needs response from OP label Jul 12, 2023
@xriter
Copy link
Author

xriter commented Jul 12, 2023

@ematipico You are right. It appears to be correct in the production mode. Only in development mode it gives the unexpected 200 OK. Is this deliberate? Or should it also just give 404 Not Found in development mode?

@ematipico
Copy link
Member

Yeah it's a bug, we'll have to look into it.

@ematipico ematipico added - P4: important Violate documented behavior or significantly impacts performance (priority) and removed needs response Issue needs response from OP labels Jul 14, 2023
@natemoo-re
Copy link
Member

Taking a look at this one now! Once #7693 is merged it should be a straightforward fix.

@natemoo-re natemoo-re assigned natemoo-re and unassigned ematipico Jul 18, 2023
natemoo-re added a commit that referenced this issue Jul 18, 2023
* chore: update tests

* chore: update tests

* fix(#7516): set response status to 404 when rendering 404 page

* chore: add changeset

* chore: update dev container test

* refactor: improve status handling logic

* chore: remove unused import
@bondarenkovladislav
Copy link

Hi, the issue is still here.
If I go to the 404 page directly it returns a 200 status, like the page exists and route too.

In Dev mode, it returns a 404, but after the build it's 200.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants