Theo van der Zee
Theo van der Zee

Reputation: 229

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?

Upvotes: 0

Views: 519

Answers (1)

David Jacquel
David Jacquel

Reputation: 52829

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.

Upvotes: 0

Related Questions