I am trying to get my error handling working. Currently, my easiest case is here: catch all errors and send to my 404.html.
In my caddyfile (I use :81 since :80 is taken), I have one route that successfully redirects. Anything else should error. I’ve copied the code directly from the handle_errors documentation.
My “error” is that I am NOT getting an error. I don’t get my 404.html and I don’t get status: 404.
curl -v http://localhost:81/bogus
Expected: Status: 404. Page: 404.html (rendered template)
Got: Status 200. No content.
2. Error messages and/or full log output:
curl -vL http://localhost:81/bogus
* Trying 127.0.0.1:81...
* Connected to localhost (127.0.0.1) port 81 (#0)
> GET /bogus HTTP/1.1
> Host: localhost:81
> User-Agent: curl/7.88.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: Caddy
< Date: Thu, 18 Jan 2024 17:20:51 GMT
< Content-Length: 0
<
* Connection #0 to host localhost left intact
* {
# First handle your known routes however you want to
handle /ha {
rewrite * <url_to_forward_to>
}
# Everything not already handled is a 404
handle * {
error "Not found" 404
}
# Now handle the 404 (and any other errors)
handle_errors {
rewrite * /404.html
templates
file_server
}
}