What a clean setup looks like
Pick one version of the site (https with or without www, either works) and send the other three straight to it with one permanent redirect each. For example, with https://example.com/ as the main address:
- http://example.com/ → 301 → https://example.com/
- http://www.example.com/ → 301 → https://example.com/
- https://www.example.com/ → 301 → https://example.com/
- https://example.com/ → 200
What each flag means
- Temporary redirect: a 302, 303 or 307. Google's documentation treats 301 and 308 as permanent, which its indexing uses as a signal that the target should be canonical; 302, 303 and 307 are followed but not used that way. For moving between http/https and www/non-www you want 301 or 308.
- More than one hop: for example http://www → https://www → https://. Each hop is another round trip for visitors. Google's crawlers follow up to 10 hops by default, so short chains still work, but one hop is cleaner.
- Different final addresses: two versions end at different URLs, so the site is effectively served on two hosts.
- Ends on http: a version is served without HTTPS.
- Loop or too many redirects: the browser gives up with ERR_TOO_MANY_REDIRECTS. We stop after 10 hops.
Where redirects usually come from
- The CDN: Cloudflare's HTTPS enforcement and redirect rules, or similar settings on other CDNs.
- The web server: a return 301 line in nginx, or RewriteRule lines in Apache's .htaccess.
- The application: WordPress redirects to the address in Settings > General (WordPress Address and Site Address), and many site builders have a primary domain setting.
- The hosting panel: a "force HTTPS" or "redirect to www" switch.
When two layers redirect at once
Most chains and loops come from two layers that each redirect. A typical one: Cloudflare's SSL/TLS mode is Flexible (Cloudflare talks to your server over plain http) and the server redirects every http request to https. Cloudflare's documentation says this loops, and the fix is to remove the server's https redirect or switch the encryption mode to Full or higher, which needs a certificate on the server.
Choose one layer for the redirect, usually the one closest to the visitor, and turn the others off.