webzod
account

Redirect www and apex to one host on Cloudflare

headers.redirect.www_split · effort: minutes

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

  1. Make sure both DNS records are Proxied (orange cloud); redirect rules only run on proxied traffic.
  2. 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.
  3. 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.

Read the documentation (opens in a new tab)

Scan your domain to see whether this applies to you.