Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Page Rules migration guide with more information #14737

Closed
Cherry opened this issue May 24, 2024 · 2 comments
Closed

Update Page Rules migration guide with more information #14737

Cherry opened this issue May 24, 2024 · 2 comments
Assignees
Labels
content:edit Request for content edits documentation Documentation edits product:rules Related to rules

Comments

@Cherry
Copy link
Contributor

Cherry commented May 24, 2024

Existing documentation URL(s)

https://developers.cloudflare.com/rules/reference/page-rules-migration/

What changes are you suggesting?

Currently this guide is missing information on the following examples. Many of these are where people struggle during migration and need extra care and attention:

Matching paths

Matching paths is much more complex with other Rules products compared to Page Rules. For example:

Page Rule: https://jross.dev/test/*/*.zip
Equivalent Ruleset Engine: http.host eq "jross.dev" and lower(http.request.uri.path) matches "^/test/[^/]+/.*\.zip$
(or something more complex without regex)

The migration guide doesn't really go into matching paths at all and ideally should be extended to showcase some examples here.

Regex

Regex is required for a lot of rules to match more complex paths, especially compared to wildcards previously.

Regex is also only available on paid plans though, so some functionality that was possible on free plans is not possible with other Rules products today, and this need to be described.

Case Sensitivity

Page Rules were case insensitive (in matching). Other Rules products are case sensitive, and to match the same behaviour, you need to wrap any functions in lower() or similar before doing checks.

This difference should probably be mentioned so people don't hit any obscure edge-cases when migrating their rules.

Wildcards

I have a thread on the forum that details this more: https://community.cloudflare.com/t/page-rules-are-now-deprecated-without-good-replacements/656245?u=cherryjimbo

But essentially recreating a Page Rules redirect with www.jross.dev/*/downloads/*/*.txt and downloads-$2.jross.dev/texts/$1/$3.txt, ends up looking something like this:

{
  "name": "default",
  "phase": "http_request_dynamic_redirect",
  "kind": "zone",
  "rules": [
    {
        "expression": "http.host eq \"www.jross.dev\" and http.request.uri.path matches r\"^/.*/downloads/.*/.*\\.txt$\"",
        "action": "redirect",
        "action_parameters": {
          "from_value": {
            "target_url": {
              "expression": "regex_replace(http.request.uri.path, r\"^/(.*)/downloads/(.*)/(.*)\\.txt$\", \"https://downloads-${2}.jross.dev/texts/${1}/${3}\")"
            },
            "status_code": 301,
            "preserve_query_string": true
          }
        }
      },
    {
      "expression": "http.host eq \"www.jross.dev\" and http.request.uri.path matches r\"^/.*/downloads/.*\\.txt$\"",
      "action": "redirect",
      "action_parameters": {
        "from_value": {
          "target_url": {
            "expression": "regex_replace(http.request.uri.path, r\"^/(.*)/downloads/(.*)\\.txt$\", \"https://downloads.jross.dev/texts/${1}/${2}\")"
          },
          "status_code": 301,
          "preserve_query_string": true
        }
      }
    }
  ]
}

This is much more complex, and as far as I can tell, impossible today on plans that do not have access to Regex - wildcard support is coming, but isn't available to folks yet.

Additional information

No response

@Cherry Cherry added content:edit Request for content edits documentation Documentation edits labels May 24, 2024
@github-actions github-actions bot added the product:rules Related to rules label May 24, 2024
@pedrosousa
Copy link
Contributor

Hi @Cherry
Thank you for all the context. These future improvements are in our radar, and we will expand the migration guide in the upcoming weeks.

@pedrosousa
Copy link
Contributor

Hello again!
Since this issue was opened, we've done numerous updates to our public documentation. We've also introduced wildcard matching support (with operators for case-sensitive and case-insensitive matching) on all Cloudflare plans so that rule expressions are easier to write.
Also, Page Rules are not going away for the time being. And when the time comes, Cloudflare will perform the migration for you.

This matter was also discussed in the following Community thread (which you created):
https://community.cloudflare.com/t/page-rules-are-now-deprecated-without-good-replacements/656245/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content:edit Request for content edits documentation Documentation edits product:rules Related to rules
Projects
None yet
Development

No branches or pull requests

2 participants