Setting Caddy to be used as an SPA (with Traefik context) : too many redirects

Hello, I would like to setup both an API and a VueJS project that would communicate together via Docker (and Traefik)

I created the following configuration after reading this question, but now I get a “Too many redirections” problem just by reaching the website

root /home/hyperforms-front/index.html

rewrite { 
    to {path} {path}/ /

Please understand that I have no idea of what I’m doing, I tried a lot of different configurations and this one is the first one that doesn’t return “404”

Thank you in advance

This isn’t a correct usage of root - you use it to specify the directory of the web root, not the index file. You should strip the /index.html from the end there.

For a request to / for your given Caddyfile, Caddy will be looking for some index file like /home/hyperforms-front/index.html/index.html, which I expect doesn’t exist.

I’m going to be honest, though - I have no idea why in particular indicating a file as the web root produces infinite redirection. I suspect it’s got something to do with the static fileserver, which redirects requests for index files back to the directory itself. It’s not got to do with the rewrite (the redirects still happen if you remove it).

Thank you for your answer, and it looks like the bad the bad use of “root” was the reason of these redirections! I now have other problems, but it’s not linked to Caddy (well, as far as I know)

Thank you!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.