Cloudflare Docs
Visit Pages on GitHub
Set theme to dark (⇧+D)

Redirecting www to domain apex

In this guide, you will learn how to redirect the www subdomain to your apex domain ( This is a common question and can be achieved by using Page Rules.

To do this, create a DNS record for the www subdomain. It must either be an A record with the value or an AAAA record with the 100:: value. The new DNS record must also have Cloudflare’s proxy enabled (orange-clouded) so that it can enact the Page Rule behavior that you will create next.

Adding a www record in the Cloudflare DNS dashboard

Next, make the Page Rule which will handle the redirect. For this, you will make it so all paths get redirected. This is done with a 301 (Permanent Redirect). Matching all paths allows for someone visiting to be redirected to

To do this:

  1. Go to Rules in the dashboard.
  2. Select Create Page Rule.
  3. Set the target to*, the /* is what matches all paths.
  4. Select Forwarding URL from the dropdown and select the 301 - Permanent Redirect option from the status code dropdown.
  5. Finally, for the Forwarding URL location, set it to$1, the $1 will be replaced by the wildcard match in target (the *).

Editing a Page Rule to set up a redirect

Finally, select Save and wait a few seconds for your rule to propagate.