webzod
account

Redirect HTTP to HTTPS on Caddy

headers.redirect.no_redirect · effort: minutes

Why it matters

Visitors who type the bare domain or follow an old link land on the unencrypted site and stay there. A permanent redirect sends every http request to the same page over https.

Staged change. Do this in stages and check each one before the next, so a mistake does not break your site or your mail.

The fix

  1. Caddy redirects http to https automatically for sites addressed by host name. Change a site address written as http://example.com or :80 to example.com.
  2. Remove auto_https off or auto_https disable_redirects from the global options if present, then reload Caddy.
  3. If the site is behind Cloudflare or another CDN that connects to this server over plain http (Cloudflare Flexible mode), this redirect loops. Switch the CDN to Full (strict) first, or redirect at the CDN instead (Always Use HTTPS).

The examples use example.com. Replace it with your own domain.

Read the documentation (opens in a new tab)

Scan your domain to see whether this applies to you.