Skip to content

feat(cli): domain set --redirect for hosts that 301 to the site's domain - #60

Merged
Madraka merged 1 commit into
mainfrom
feat/domain-redirect
Oct 21, 2026
Merged

Madraka merged 1 commit into
mainfrom
feat/domain-redirect

Conversation

@Madraka

@Madraka Madraka commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Closes #49.

cloudhal domain set example.com --redirect www.example.com (repeatable, or comma-separated):

  • cloudhal.json → domains.redirects.
  • The next cloudhal deploy routes each host to the site Worker as a Cloudflare Custom Domain (DNS record and certificate created by Cloudflare) and sets CLOUDHAL_REDIRECT_HOSTS / CLOUDHAL_REDIRECT_TO.
  • The site Worker answers those hosts first, before picking a site: 301 to https://<site domain><path><query> (packages/astro-renderer/src/host-redirect.ts).
  • cloudhal domain remove redirects drops them; removing the site domain drops them too (nowhere to go). A redirect host equal to the site's or Studio's domain is refused.

This replaces the hand-made Cloudflare Redirect Rule cloudhal.com uses for www.

Tests: host-redirect.test.ts (301, path/query kept, other hosts untouched); deploy.test.ts checks validation, the routes and the vars in the generated wrangler.jsonc.

🤖 Generated with Claude Code

`cloudhal domain set example.com --redirect www.example.com` records the
redirect hosts in cloudhal.json (`domains.redirects`). The next deploy routes
them to the site Worker as Custom Domains (so Cloudflare creates the DNS
records and certificates) and names them in CLOUDHAL_REDIRECT_HOSTS /
CLOUDHAL_REDIRECT_TO; the Worker answers them with a 301 to the site's
domain, path and query kept, before picking a site. `domain remove
redirects` drops them; removing the site domain drops them too.

Closes #49

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Madraka <[email protected]>
@Madraka
Madraka merged commit b631484 into main Oct 21, 2026
4 checks passed
@Madraka
Madraka deleted the feat/domain-redirect branch October 21, 2026 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

domain: redirect www (or another host) to the primary domain

1 participant