Stripping the URL suffix lead to a blank screen

I’m confused, are you using Traefik in front of Caddy?

You could just replace Traefik entirely with Caddy, instead. This plugin will let you configure Caddy using docker labels:

So, you’re actually doing this in the wrong direction – what you want to do is if a request comes in without .html, then you want to see if adding .html to the path will map to a file on disk. Directives like uri strip the prefix after Caddy gets the request, which doesn’t quite make sense.

So right now, if you get a request for /foo.html, then you’re removing the .html and looking on disk for a file called /srv/foo, which won’t exist.

You want to do the opposite, where if you get a request for /foo, you try adding .html to look on disk for /srv/foo.html, and if that exists, rewrite to that path.

This is done with the try_files directive:

try_files {path}.html

This is basically a shortcut for this equivalent config:

@try_files file {path}.html
rewrite @try_files {http.matchers.file.relative}
1 Like