Redirect www and apex to one host on Cloudflare
Why it matters
Both names serve the site, so search engines see duplicate pages and logins, cookies and HSTS are split between two hosts. Pick one canonical host and permanently redirect the other to it.
The fix
- Make sure both DNS records are Proxied (orange cloud); redirect rules only run on proxied traffic.
- Open Rules, Overview, choose Create rule, Redirect Rule, and fill it in as below (or start from the redirect from WWW to root template). Deploy.
- To make www canonical instead, swap the two host names.
text
Rule type: Redirect Rule, Wildcard pattern Request URL: https://www.example.com/* Target URL: https://example.com/${1} Status code: 301 Preserve query string: on
The examples use example.com. Replace it with your own domain.
Related
- Reported by the HTTP to HTTPS redirect check
- Serve the site over HTTPS
- Stop redirecting HTTPS to HTTP
- Redirect HTTP to HTTPS
- Fix the broken HTTPS redirect chain
- Shorten the redirect chain
- Fix the HTTP redirect chain
- Redirect HTTP straight to HTTPS
- Answer HTTP with a redirect to HTTPS
- Make the www or apex name work over HTTPS
Scan your domain to see whether this applies to you.