2023-05-23
Written by Zed Kaido
How to Add www Support to
Cloudflare Pages
If you use cloudflare pages, and like me, tried visiting www.website.com only to find out that it was not available - you are in the right place. This article provides some direction on how to setup redirection of www.website.com to website.com and vice-versa using page rules.
Redirecting www.website.com to website.com
- Open your Cloudflare Dashboard: https://dash.cloudflare.com
- Go to: Websites > website.com > DNS
- Add a DNS record for www to website.com:
- Type: A
- Name: www
- IPv4: 192.0.2.1
- Go to: Rules > Create Page Rule
- URL: www.website.com/*
- Setting: Forwarding URL
- Status Code: 302 - Temporary Redirect (to start with)
- Destination URL: https://website.com/$1
- Voila! www.website.com is now accessible!
- If this is the desired effect you want, change the Status Code from "302 - Temporary Redirect" to "301 - Permanent Redirect"
Note: The asterisk * means it will forward all pages, and the $1 will keep the path intact: www.website.com/page → website.com/page
Redirecting website.com to www.website.com
- Open your Cloudflare Dashboard: https://dash.cloudflare.com
- Go to: Websites > website.com > DNS
- Add a DNS record for @ to website.com:
- Type: A
- Name: @
- IPv4: 192.0.2.1
- Go to: Rules > Create Page Rule
- URL: website.com/*
- Setting: Forwarding URL
- Status Code: 302 - Temporary Redirect
- Destination URL: https://www.website.com/$1
- Voila! website.com will redirect you to www.website.com!
- If this is the desired effect you want, change the Status Code from "302 - Temporary Redirect" to "301 - Permanent Redirect"