Web / Caddy Server Interview questions
How do you redirect HTTP to HTTPS in Caddy?
Caddy already redirects plain HTTP to HTTPS by default whenever automatic HTTPS is active for a domain, so most sites need no extra directive at all - Caddy adds an implicit redirect on port 80.
www.example.com { redir https://example.com{uri} permanent } example.com { file_server }
The example above shows an explicit case: redirecting a www host to the bare domain. redir takes a target URL (the {uri} placeholder preserves the original path and query string) and a status code keyword - permanent sends a 308, while temporary sends a 302. Explicit redir blocks like this are for custom redirect rules, not for the baseline HTTP-to-HTTPS behavior, which Caddy already handles.
More Related questions...