1

I am following backblaze's instructions to serve a static webpage through cloudflare.

Part of this involves creating a cloudflare 'page rule' which directs from the domain to the backblaze bucket, for example the forwarding rule:

example.com -> https://f000.backblazeb2.com/file/example-bucket/index.html

This works to serve the page. The one problem I have is with the url that appears in the browser's address bar. Instead of example.com it shows f000.backblazeb2.com/file/example-bucket/index.html. Is there a cloudflare page rule that can serve the backblaze bucket while keeping the original domain appearing in the browser's address bar?


UPDATE:

I found that with a 'Forwarding URL' page rule with origin URL https://example.com/ and destination URL https://example.com/file/example-bucket/index.html, then when navigating to example.com the browser will at least display example.com/file/example-bucket/index.html in the address bar. This at least verifies to the user that what they are looking at is under the intended domain. It would still be good to have just the domain appear without the following /file/example-bucket/, as that is not relevant to the organization of the site, only to the bucket in which the content is stored. Is there a way to get something more like example.com/index.html from example.com/file/example-bucket/index.html?

mherzl
  • 193

1 Answers1

2

When a Forwarding URL page rule is triggered, Cloudflare returns a 302 Found (aka redirect) HTTP status code with the Location header set to the URL you specify, rather than proxying the request to the origin. Hence you were originally seeing the browser loading the https://f000.backblazeb2.com/file/example-bucket/index.html page.

Rather than a Forwarding URL page rule, you need a Transform Rule, specifically a Rewrite URL rule, so that Cloudflare rewrites the URL before proxying the request to the origin.

In your Cloudflare domain:

  1. Navigate to Rules > Transform Rules.
  2. Click Create Rule.
  3. Give the rule a descriptive name, e.g. "Rewrite root to index".
  4. Under When incoming requests match…, Click Custom filter expression.
  5. Set Field to "URI Full", Operator to "equals", and Value to the root of your domain, e.g. https://example.com/.
  6. Under Set Rewrite parameters > Path, Click Rewrite to....
  7. Select Static and enter the target path, without the leading '/', e.g. file/example-bucket/index.html.
  8. Click Deploy.

Now, when the incoming URL matches https://example.com/, Cloudflare rewrites the path to file/example-bucket/index.html, so it requests https://f000.backblazeb2.com/file/example-bucket/index.html from the origin, but the URL in the browser will remain https://example.com/.

metadaddy
  • 179