| zedkaido.com > writing | RSS

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

  1. Open your Cloudflare Dashboard: https://dash.cloudflare.com
  2. Go to: Websites > website.com > DNS
  3. Add a DNS record for www to website.com:
    • Type: A
    • Name: www
    • IPv4: 192.0.2.1
  4. 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
  5. Voila! www.website.com is now accessible!
  6. 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/pagewebsite.com/page


Redirecting website.com to www.website.com

  1. Open your Cloudflare Dashboard: https://dash.cloudflare.com
  2. Go to: Websites > website.com > DNS
  3. Add a DNS record for @ to website.com:
    • Type: A
    • Name: @
    • IPv4: 192.0.2.1
  4. Go to: Rules > Create Page Rule
    • URL: website.com/*
    • Setting: Forwarding URL
    • Status Code: 302 - Temporary Redirect
    • Destination URL: https://www.website.com/$1
  5. Voila! website.com will redirect you to www.website.com!
  6. If this is the desired effect you want, change the Status Code from "302 - Temporary Redirect" to "301 - Permanent Redirect"

2023-05-23
by Zed Kaido