Redirect HTTP to HTTPS instead of answering an error

headers.redirect.no_redirect_error · effort: minutes

Why it matters

Visitors who type the bare domain or follow an old http:// link get an error page instead of the site. 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. Stage 1: confirm that https://example.com/ serves every page you are about to redirect to.
  2. Stage 2: make the port 80 site answer every request with a 301 redirect to the same host and path on https:// instead of the error page.
  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).
  4. Check it with curl -sI http://example.com/ and expect the response below.
http
HTTP/1.1 301 Moved Permanently
Location: https://example.com/

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.