Hi,
I struggled with getting Cloudflare’s URL Transform rule system to work with Unity WebGL project sitting in a R2 subfolder. Here are my notes for the working solution to reach the project on https://example.com URL, which is sitting in your_r2_bucket/your_folder/:
== Unity WebGL hosted on Cloudflare R2 ==
pre:
- (if you want videos played search for StreamingAsset folder use)
- when building the project set the compression to 'none'
- upload the whole folder to R2 so it's public access URL would be like https://example.com/your_folder/ ...
rules in Cloudflare:
1) create a Redirect rule:
- If incoming request match...
custom filter expression: (not http.request.uri.path contains "." and not ends_with(http.request.uri.path, "/"))
- Then...
URL redirect
type: dynamic
expression: concat(http.request.uri.path,"/")
status code: 301
preserve query string: true
I placed it as the last Redirect rule after a separae http->https and a www->root rule. Name it as you see fit.
2) create Transform rule:
- If incoming request match...
custom filter expression: (not starts_with(raw.http.request.uri.path, "/your_folder"))
- Then...
Set Rewrite parameters,
Rewrite to....
type: dynamic
expression: concat("/your_folder", raw.http.request.uri.path)
preserve query string: true
I placed it as first Transform rule. Name it as you see fit.
3) create Transform rule:
- If incoming request match...
custom filter expression: (ends_with(http.request.uri.path, "/") and not http.request.uri.path contains ".")
- Then...
Set Rewrite parameters,
Rewrite to....
type: dynamic
expression: concat(http.request.uri.path,"your_folder/index.html")
preserve query string: true
I placed it as Transform second rule. Name it as you see fit.