Join the community today
Become a Member

Cloudflare Don't forget: how to set up www redirects with Cloudflare Page Rules

Discussion in 'Domains, DNS, Email & SSL Certificates' started by deltahf, Jul 5, 2018.

  1. deltahf

    deltahf Premium Member Premium Member

    Jun 8, 2014
    Local Time:
    1:11 AM
    When I activated Cloudflare on my site, something which I forgot/didn't realize I would need to configure was the automated www redirects. I run my site with a www subdomain (, and redirect all non-www traffic ( to the www version with 301 redirects configured in Nginx.

    I didn't see this mentioned anywhere, so I thought I would put together a super-easy tutorial that might serve as a reminder for others in the future.

    Just create a new Cloudflare "Page Rule" with the following settings:

    Screen Shot 2018-07-04 at 10.32.17 PM.png

    Because only one Page Rule can be applied to any given request, make sure this rule is defined FIRST.

    Finally, note the "$1" in the forwarded URL. This variable ensures that anything caught by the wildcard will be in the new URL, so "" will redirect to "".

    Hope this helps someone in the future.

    Last edited: Jul 10, 2018
  2. eva2000

    eva2000 Administrator Staff Member

    May 24, 2014
    Brisbane, Australia
    Local Time:
    3:11 PM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    there's actually HTTPS auto rewrite option and always use HTTPS options you can enable then just remove any nginx level http to https redirects but yes you need that page rule if you want to favour one version www or non-www

    or you can do non-www https to www https redirect at nginx level