Caddy 2 multidomains rewrite

Hello, I’m developing a multidomain site using Django and Caddy 2(with Cloudflare plugin)
The project has about 20 domains:
and so on…
I wanna catch requests to domains and rewrite them to some etc…
What you think is better way of doing this?

Assuming the TLD maps 1-to-1 to the subfolder you want, you could do something like this:,,,,, {
  @secondary {
    not host
  rewrite @secondary /{}{uri}

  # rest of the site config goes here

Then requests to will be treated as a request to A request like will be treated as


Thanks, I’ll try this. I even didn’t seen these {} in docs.

Aye, I actually meant to put some docs references down! I just forgot :joy:

It’s a little less discoverable if you’re a Caddyfile-only user (i.e. avoiding the JSON) - it’s documented in the http app itself: Modules - Caddy Documentation

1 Like

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