Community Tip - Best Practices For Page Rules

CommunityTip

#1

Scope
Follow the suggestions in this Community Tip to help understand best practices for working with Cloudflare Page Rules.

Background
Cloudflare Page Rules give you the ability to take various actions based on the page’s URL, such as creating redirects, fine tuning caching behavior, or enabling and disabling services. Note that only one Page Rule takes effect on any given request, page rules are given priority in an order from top to bottom, and once a URL matches a rule, only that rule only will be applied, any subsequent rules that also match the URL pattern will not take effect. As a general rule, order rules from most specific to least specific.

Troubleshooting & Rule-Specific Discussion

  1. Must-Use Page Rules for Everyone

  2. Redirect from www.example.com to example.com
    If the URL matches - www.example.com/*
    CLICK “+ A Setting” and select “Forwarding URL”
    Select Status Code - “301 Permanent Redirect”
    Enter Destination URL - example.com/$2
    CLICK Save and Deploy

  3. Redirect from example.com to www.example.com
    If the URL matches - example.com/*
    CLICK “+ A Setting” and select “Forwarding URL”
    Select Status Code - “302 Temporary Redirect”
    Enter Destination URL - www.example.com/$2
    CLICK Save and Deploy

  4. Direct visitors to a specific page with an easy to remember URL:
    If the URL matches - *www.example.com/cf*
    CLICK “+ A Setting” and select “Forwarding URL”
    Select Status Code - “302 Temporary Redirect”
    Enter Destination URL - www.cloudflare.com/plans/
    CLICK Save and Deploy

Lite Reading

Background Resources
Knowledge Base
YouTube

Research The Issue
Community
Google

If You Need More Help
This community of other Cloudflare users may be able to assist you, if not, login to Cloudflare and then contact Cloudflare Support.

Expert Comments Appreciated
This Community Tip will remain open for input from Community experts and those familiar with Page Rules. We really appreciate comments that start with things like, “try this rule, it is useful when”, “I’d edit the rule to”, or “that rule will introduce a loop, try this”.

This is a Cloudflare Community Tip, to review other tips, click here.


#2

On the

page, the tutorial video appears to be broken! Just wanted to let you know!

@cloonan @cscharff @ryan


#3

Also adding to @domjh the second or the third examples are wrong, you should probably remove the https:// and the * to make sure to cover only those specific subdomains/root with and without HTTPS.