How to Create a Redirect for www on Cloudflare
When you host a site on Cloudflare it is a good idea to create a redirect from www to your main domain.
If you don’t have a www redirect in the Cloudflare DNS records, then you will see this alert:
Add an A, AAAA, or CNAME record for www so that www.mysite.com will resolve.
This is how you do that.
Step 1: Create a CNAME record
- In the Cloudflare dashboard select your website.
- Then in the left side menu select DNS >> Records.
- Click the “Add record” button and add the following record:
| Type | Name | Content | Proxy status | TTL |
|---|
CNAME | www | mysite.pages.dev | Proxied | Auto |
Step 2: Create a redirect page rul
- In your Cloudflare dashboard select your website.
- Then in the left side menu select “Rules” >> “Page Rules”.
- On the “Page Rules” page, click the “Create Page Rule” button.
- On the “Create a Page Rule for mysite.com” page, enter/select the following:
- In the “URL” field enter:
www.mysite.com - Pick a Setting:
Forward URL - Enter destination URL:
mysite.com - Click the
Save and Deploy Page Rule button.
That’s it! You are done.
Sources