How to Redirect Apex Domain to www in Cloudflare
Publish date: Jul 5, 2024
Last updated: Jul 28, 2024
Last updated: Jul 28, 2024
1. Set up DNS records
Create corresponding DNS A or CNAME records for the apex and subdomain.
![](/how-to-redirect-apex-domain-to-www-in-cloudflare/dns-records_hucf1420555f13b9f5b4dcd3e981f882bf_97027_700x0_resize_box_3.png)
2. Use Cloudflare DNS
Go to your registrar and add the Cloudflare Nameservers.
![](/how-to-redirect-apex-domain-to-www-in-cloudflare/registrar-custom-dns_hu033e8f1e1a3c477d9eb3baac4f827a0d_20550_700x0_resize_box_3.png)
3. Create a redirect rule
Go to Redirect Rules and create a new rule.
When incoming requests match
Using the Expression Editor:
(lower(http.host) eq "example.com")
Then
Type: Dynamic
Expression: concat("https://","www.example.com",http.request.uri.path)
Status code: 301
![](/how-to-redirect-apex-domain-to-www-in-cloudflare/apex-to-www-redirect-rule_hu31f655a07ed7735a1bbc8c8e3e79f2e1_80978_700x0_resize_box_3.png)
Ref:
Cloudflare Docs, Redirect the apex domain to a subdomain