I'm creating spa application, using react. Whe i have url which is not in base of routes, I'm redirectng client into error page and showing him information that this is 404 page and current url is not working. But when this page is opened, Status code of this page is 200, but should be 404. As i understood, display 200 status code on 404 page is bad for seo optimization. How can I return 404 status code, when I'm opening 404 page?
Asked
Active
Viewed 275 times
0
-
3Does this answer your question? [How do I return a HTTP 404 status code from a SPA?](https://stackoverflow.com/questions/37334220/how-do-i-return-a-http-404-status-code-from-a-spa) – Asplund Apr 28 '23 at 11:40
-
@Undo, I need return status code 404, not only do thing for noindex page) – Nikita Apr 28 '23 at 11:46
-
The server responds with status codes, if a 404 is calculated on the client side you can't change the status code. In that case you must do some trickery with redirections to a real server rendered 404 page which is not worth it. Google is ok with a 200 page with the no index meta and a 404 error message. Lots of client rendered sites do this. – Asplund Apr 28 '23 at 11:56
-
@Undo, but I need to render 404 page with status code 404, not with 200. We don't have any reasons to do what I want? – Nikita Apr 28 '23 at 12:40
-
If your website is rendered by the server, you can easily set the status code to You can't set a status after the server response is sent to the client. – Asplund Apr 28 '23 at 13:42