How can i make Gatsby's custom 404 page to return 404 status code - http-status-code-404

I have a custom 404 page and its working fine. When the user has a non existed url, lets say example.com/abcd, they are redirected to the 404 custom page. But the 404 custom page has 200 status code, that is not good for SEO. And as I read some information, this is normal behaviour because the 404 page exists.
But is there any chance to make this page to return 404 status code?
Gatsby version is 2.17.11.

Related

How to Stop Redirecting to 404 page When page Not found in Next.js

I want to stop redirecting to 404 page when page not found in my next.js app. I just want to show my 404 component without redirecting or changing URL.
Currently, next.js redirecting to 404/ URL.
Is there any ways?
Thanks!
The Next.js framework has built-in ways for handling 404, 500, and other errors that may occur on your website. But to add custom layout and styling to those pages, you'll need to create both a /pages/404.js and /pages/_error.js file.
When one of those errors occur, Next.js will render that page instead of the default page it would otherwise automatically generate.
The /pages/404.js file will handle all 404 related errors. And the /pages/_error.js file will handle 500 type errors.
here's official documentation customizing 404
You can create custom 404 page in NextJS with creating file in
/pages/404.js
You can create page for 404 error.
For more Details click here

React app SPA on S3 AWS while refreshing the page shows 404 page

I have a SPA made with React JS on a S3 Bucket and I’m using Cloud Front to work through HTTPS and with a custom domain. When I refresh the page - if I have another Route that is not the BASE_URL (for example domain.com/something), S3 sends me a 404 error.
I also tried redirecting the error page to BASE_URL but it doesn’t work, it redirects me to the Http default domain that S3 provides me and again, it gives me an 404 error page.
I don’t know if there exists an alternative way to keep the URL without any change (domain.com/page) and avoid the 404 error the way a web server (apache) handles.
If you are using CloudFront to host s3 website, the effective way to get rid of 404 on reload of non-index route like www.google.com/about or similar non / is by the following steps:
Go to your CloudFront distribution
Go to Error Pages
Create a new error page with the following params:
HTTP Error Code: 404
TTL: 0
Custom Error Response: Yes
Response Page Path: /index.html
HTTP Response Code: 200
enjoy
credits going to this article https://gist.github.com/bradwestfall/b5b0e450015dbc9b4e56e5f398df48ff
You have two options. Either use CloudFront error page as a catch-all that redirects to / (you mentioned you tried setting an error page but did not detail what you did. This should work). The downside is that it will respond with the HTML page for all not found paths, even for mistyped CSS paths, for example.
The other solution is to use Lambda#Edge to rewrite the origin request path. This is a more customizable solution and you can define which paths you want to redirect to the root.

Change HTTP status code in Jekyll

I'm using Jekyll to generate my website. When you add a file called 404.html to your web root and a page isn't found in a Jekyll website, then Jekyll will automatically display the contents of the 404.html file to the user. However, it does so with an unchanged URL (but, with a correct HTTP status return code of 404).
In order to be able to log errors in Google Analytics (and set a Custom Alert to alert me of any 404's), I want to forward the error page to /404/?broken=url-goes-here. This page unfortunately, returns a HTTP status code of 200. This leads to the main question:
How do I get a page to return a different status code than 200 in Jekyll? The original page that is fetched upon an error correctly returns 404, but my /404/ page returns 200, and I want it to return 404 (preferably without using any Jekyll Plugins, AJAX or Javascript).
Anyone?
In Github pages, you can set a custom 404.html page.
The name must be 404.html.
The http returned code is 404.
You can then catch this in analytics.

Apache custom 404 page that returns 404 error

I have a custom 404 error page on my apache (404.php) and it works normally, but if someone or any search engine requests the /404.php page, the server returns 200 (OK), because the page actually exists.
I have already put the Disallow: /404.php on my robots.txt file to prevent Google from indexing that page, but I'd like to return 404, including to this page request.
Is there a way to also return 404 when someone reaches the 404.php directly?
I just whipped this up really quickly:
<?
header("HTTP/1.1 404");
echo "ERROR"; // Put the contents of your 404 page here.
?>
I checked it in Chrome, and this will return a 404 code in the header, and let you write whatever you'd like to the rest of the page. Just put the header function at the beginning of the page.

What is the permalink or URL for a 404 page in WordPress?

I am trying to validate the HTML on my 404 page for a WordPress theme, but obviously, the validator cannot find the page, because it doesn't exist.
http://cambridgeuplighting.com/agsdfachgsd
http://cambridgeuplighting.com/404a234
Or any false link will generate the 404 page, but what's the actual url for this page?
Thanks!
Most systems don't expose a 404 error page with a 200 status code. Tick the Validate error pages option at http://validator.w3.org/#validate_by_uri+with_options instead.
There isn't one, really. Your best bet is:
find the bit in Wordpress which sets the 404 header and comment it out. (I gave it a quick go, but failed)
If you're using firefox, install this addon: https://addons.mozilla.org/en-US/firefox/addon/249 which will validate the page inside the browser. (This seems to be the same kind of thing for Chrome, but I haven't tried it: https://chrome.google.com/extensions/detail/cgndfbhngibokieehnjhbjkkhbfmhojo )
download the pure HTML for the page and upload it.

Resources