This proxies all requests to a folder in the S3 bucket which name matches the domain name in the request. The main limitation, as you can see, is that there’s a 1-1 mapping between domain names and folders in the S3 bucket, so each folder matches one and only one domain name.
We also want to support accessing those sites using the www. subdomain of those custom domains, therefore my question: is it possible to set a generic redirect rule in Caddy to redirect allwww. subdomains to their non-www counterpart?
I thought of creating a new server block using www.*:443 and placing a redirect rule inside, but I’m not sure if/how I can get the non-www domain name from that.
I don’t believe it’s possible to manipulate the host/domain via Caddyfile currently (such as identifying and removing the www. as you require). rewrite operates on the URI, and redir has no regex functionality.
This would probably require extending Caddy itself.
You got me there. You can’t take matched groups out of the if subdirective to use in the redirect target, though, I understand. That would probably be pretty handy for this use case.
We’ve finally opted to add a fastcgi backend with a simple PHP script that does the redirect. Is not optimal, but it’s the only option we found so far.
Just in case someone is interested, this is how the Caddyfile looks like now:
This is a major bummer for me right now
I need generic redirects based on the first part of host name, also to be able to set some context variable for dev.* domain names.
Cheers.