-
Notifications
You must be signed in to change notification settings - Fork 57
Add canonical host redirect feature #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Implements host canonicalization to redirect requests to a single host (e.g., force root or www). Works with TLS redirect in a single hop (e.g., http://www -> https://root). Changes: - Added CanonicalHost to ServiceOptions - Centralized redirect logic to compute both scheme and host in one place - Exposed --canonical-host flag in deploy command - Added comprehensive tests for canonical host redirects including TLS cases This feature is backwards compatible and only active when configured. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Would love to get this merged! |
Having 2 hosts is fine but there should be a way to configure redirections from one to the other so a typical use case is from |
@Talha345 i see your point. these days if you want to have a one website just use a one host, keep your website name as short as possible for humans. p.s.: create websites for humans, not for SEO. |
There could be various other use cases as well and that is out of the scope of this discussion. In general, a proxy should support this kind of basic redirection. I still have a couple of sites which are using Kamal 1 with Traefik and I simply have not upgraded to Kamal 2 for this exact reason. |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @JangoCG. This feature seems like a good idea to me!
I've left some small suggestions about the details. Let me know what you think. I'm also happy to address those myself if you don't have time.
I also like @AnyCPU's suggestion that if both --canonical-host
and --host
are set, we should validate that there is a --host
that matches the --canonical-host
(because otherwise, that deployment would be invalid). We can validate that is the command before attempting the deployment.
Awesome, I’m glad you like it @kevinmcconnell thank you for the review! And thanks as well @AnyCPU for your input. |
# Conflicts: # internal/server/router_test.go
Summary
Adds host canonicalization to redirect all requests to a single canonical host, e.g., force root (
domain.com
) orwww
(www.domain.com
).Supports both directions:
www.domain.com → domain.com
domain.com → www.domain.com
Redirects happen in one hop even with TLS (e.g.,
http://www
→https://root
).Changes
CanonicalHost
toServiceOptions
--canonical-host
flag todeploy
commandMotivation
Kamal currently has no built-in way to handle
www
↔ root redirects, forcing users to rely on Cloudflare or custom reverse proxy rules.This is a basic feature in most reverse proxies, and this PR makes it available natively in Kamal.
Compatibility
Backwards compatible, only active when explicitly configured.