Catch-all redirect but keep subdomain

I want to setup a catch-all redirect for domain B that redirects to domain A but keeps the subdomain and URI of the original request.
An example config could look like this:

*.B.com {
    redir {scheme}://{subdomain}.A.com/{uri}
}

Is such a redirect possible?

Any ideas how I can write such a redirect rule?

While rewrite supports regex, redir does not. Nor is there an appropriate request placeholder. It may not be possible for Caddy to perform a redir that carries the subdomain forward as you’ve specified.

If you have a list of subdomains you expect to use, you can add a directive to your Caddyfile for each one.

1 Like

Thank you for your response, I have a list of subdomains to use and I will add them manually to each directive.

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