Redirect HTTP to HTTPS before adding HSTS
Having an HTTPS address doesn't stop a visitor from following an old HTTP link. A redirect gives that request a destination on HTTPS.
Redirect HTTP to HTTPS with a permanent response
For a permanent move, use a server-side 301 or 308 redirect to the HTTPS version of the requested page. Keep the path and query string so an old link still reaches the content it names.
How do I force HTTPS on my host?
| Host | Where to set the HTTPS redirect | Source |
|---|---|---|
| Cloudflare | Turn on Always Use HTTPS after the affected hosts work over HTTPS. | Always Use HTTPS |
| nginx | Use a separate HTTP server block with a return directive pointing at the HTTPS destination. | Separate server blocks and return |
| Apache | Use Redirect permanent in a dedicated HTTP virtual host; use the documented rewrite approach if only .htaccess is available. | Forcing HTTPS |
| Vercel | HTTP requests already receive a 308 redirect to HTTPS from the CDN. | Encryption and TLS |
| Netlify | Use protocol-specific redirect rules when a host needs an explicit redirect, and assign the source domain to the site. | Domain-level redirects |
Add HSTS after the HTTP to HTTPS redirect works
Once every HTTP address redirects, add the Strict-Transport-Security header to your HTTPS responses. Leave it off the redirect itself, since browsers ignore the header when it arrives over HTTP. The HSTS reference explains why.
Frequently asked questions
Why does forcing HTTPS cause too many redirects?
Your CDN and your server can disagree about whether a request already uses HTTPS. On Cloudflare's Flexible mode, for example, Cloudflare reaches your server over plain HTTP, so a server rule that sends HTTP to HTTPS causes a loop. Cloudflare's redirect loop guide covers each setting, and Apache's guide covers servers behind a proxy.
Review HSTS, mixed content and the redirects Google sees
Domain health
Fix the setup mistakes that make browsers warn people away from your site.
HSTS
Understand how browsers remember HTTPS before extending that rule to every subdomain.
Mixed content
Replace insecure file and form addresses that remain on an HTTPS page.
Redirects
Choose the right redirect for a move and remove unnecessary steps to the destination.