I want every url except real files and /api rewritten to /index.html.
* {
rewrite / {
if {path} not_starts_with /api
to {path} {path}/ /index.html
}
proxy /api https://r.datenknoten.me
root /var/www
tls off
}
If I access / I get the index.html, but if I try to access /foo/bar/ I get a redirect to /. With my config I would expect that /foo/bar/ would serve the index.html. /api returns the API correctly.
I dont get any error logs, because from the caddy config everything seems to fine?!
I can’t see anything in that Caddyfile that would be issuing a redirect.
Could you add log / access.log "{common} - {rewrite_uri_escaped}" to your Caddyfile and then give us the output of curl -i */foo/bar as well as the resulting log?
No idea why I gave you the escaped version to use. Oh well, small matter.
Turns out, Caddy’s static fileserver is handling the request for /index.html with a permanent redirect to the canonical /, which is how the client should request an index. (more info, I see this is a recent change)
You can fix this by changing your to subdirective:
rewrite {
if {path} not_starts_with /api
to {path} {path}/ /
}
I wonder if we will see a few more people pop up with this problem soon, I believe rewriting to a specific index file is quite common.