Preserving subdomain in redirect

1. Caddy version (caddy version): 2 (Using Caddyfile)

3. The problem I’m having:

I’m aware of the redir sub.domain.tld{uri} directive, which’ll preserve the originally called URI.
However, what I want to achieve is to also preserve the originally called subdomain.

Essentially, to create a mass-redirect - for example to use when switching over to a new domain or just to utilise shorter domains for memorability.

Something like this: redir {sub}.domain.tld{uri}.

Is this possible?

6. Links to relevant resources:

Same has been asked here in 2016:

Yep! You can use {labels.2}

Request host labels (0-based from right); e.g. for foo.example.com: 0=com, 1=example, 2=foo

1 Like

Amazing! Thank you very much.

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.