Respond all 404 to 410

Hi, I need to respond all 404 pages error to 410. As for example, I have following configuration:

@404 {
header 404 ← Will this work if not how to accomplish
}
respond @404 410

Can somebody please help me change all 404 response to 410. Everything is all right, only I don’t know how to denote 404 header on Caddy 2 configuration.

Thanks!

This one didn’t worked too:

@404 {
expression {http.error.status_code} == 404
}
respond @404 410

Given that 404 is within the error range (> 400), then your respond must be used within the handle_errors directive. So you will need something like this:

@404 {
	expression {http.error.status_code} == 404
}
handle_errors {
	respond @404 410
}
1 Like

I got error connection timeout on website. I think this is something that somebody should not try to do!

Connection timeout means your client never even managed to contact Caddy successfully. You will almost never see a connection timeout caused by configuring handlers! More often it might happen if you mistakenly manipulate the site label (i.e. by specifying the wrong port or scheme) or from networking/DNS issues.

1 Like

@Whitestrake you are right! Now I know that. Thanks!

However, any of these configuration didn’t show 404 error as 410. I checked on browser.

This configuration worked for me.

~/Projects/test
➜ cat Caddyfile
http://:8080 {
  @404 expression {http.error.status_code} == 404
  handle_errors {
    respond @404 410
  }
  file_server
}

~/Projects/test
➜ caddy2 version
v2.1.0-beta.1 h1:nG+Y2NuoqGvJEnHlVO5PXtTxuc2yHsjr2nU+dJ5yETk=

~/Projects/test
➜ curl -i localhost:8080
HTTP/1.1 410 Gone
Server: Caddy
Date: Wed, 15 Jul 2020 06:30:58 GMT
Content-Length: 0

This topic was automatically closed after 30 days. New replies are no longer allowed.