Sending 418 http response

Is it possible using the _headers file to send a HTTP 418 response for specific files instead of a more standard HTTP 200?

Hey @mrcycling! Yes, you should be able to set whatever headers/statuses you want in there. Are you running into errors when you do that?

Hello @jen, I hadn’t seen any information in your documentation regarding sending an alternate http response code, so figured it was better to ask than to experiment on a system I have no control over.

How would you write the Netlify _header equivalent of:
<?php header("HTTP/1.1 418 I'm a teapot"); ?>

We use teapot placebo files for common files that hackers like to search for, rather than returning 404s and filling the logs with error messages.

Ah, what you’re describing sounds more like a redirect to me… or maybe a combo of a few different files :slight_smile: So in our _redirects file or netlify.toml, depending on the structure of your project, you’d do something like this:

/admin/config.js     /index.html     418

This says: redirect any request for /admin/config.js to /index.html with 418 status.

To get the header message, you’d have to add a _headers file in addition to the _redirects file. Or you could combine both in a netlify.toml. In the _headers, you’d do something like this:

# a path
/admin/config.js
     # header for that path
     what-am-i: "a teapot"

Here are our docs on status codes for redirects:

And our docs on custom headers:

Let me know if that helps or you have any other questions!