DDNS, with Caddy handling subdomains; each subdomain points to a different third party web application running behind my gateway using reverse proxy. One of the subdomains will be a static file server.
Letās say example.ca is just my main domain, will just point to a simple static index.html.
files.example.ca will just be a directory of files that get distributed/shared with clients often.
app.example.ca would one of the many apps we will have. I use Caddy for these as reverse proxy to supply https, handle subdomains, etc.
The issue is with app.example.ca. The app behind the proxy doesnāt handle the root subdomain (files.example.ca) very well. It just spits an error. It canāt be changed in the app. You need a URL like app.example.ca/hello/goodbye/#/p to access the web app/interface.
How would I make that Caddy points/redirects app.example.ca to app.example.ca/hello/goodbye/#/p? Iām probably not wrapping my head around the redir directive correctly.
Notably all of these examples are universal (they apply to all requests to the site). It sounds like what you want is to only redirect from the web root (/) to the path your clients need to use to satisfy the upstream server.
What you need to do is use a matcher. All directives support a matcher as their (usually optional) first argument. You want to match the path (to /) before issuing the redirect. Thus, have a look at the path matcher: Request matchers (Caddyfile) ā Caddy Documentation
Note also that the example given for a path matcher is the redir directive! It should be easy to adapt to what you need.
Hi Matt,
Sorry for the delay! Itās been crazy! I finished implementation today, but Iāve noticed Caddy only seems to forward redir / /hello/goodbye/#/p to /hello
It appears to cut out everything after the second forward slash. Do you have any suggestions? Itās critical that it redirects to everything, as the application behind the reverse proxy is picky, and canāt be configured otherwise.
Why? Remember that this symbol # indicates the start of a comment in a Caddyfile.
Getting around this is fairly easy. The Caddyfile parser counts anything in quotation marks as a single token. If you must issue a redirect to a fragment, encase it in quotes.
Oh WOW, that is something I hadnāt even considered!
Just implemented, and it worked wonderfully! I may just end up using quotes like that for all of my redirs for reverse proxying. It might just save me a headache.
Cheers, thanks for the help, youāre a life saver!
Yes, that would be incredibly sensible given the possibility of handling fragments in configuration. It IS a web server, after all. And I think people who donāt put spaces before their comment hashes must be psychopaths so it should be reasonable to expect a preceding space when weāre not on a new line.