set rules to rewrite and redirect requests through cloudflare to a public access S3 bucket

I have a public access S3 bucket, with a folder structure. I have a URL pattern (say https://<domain>/Sitemap.xml, i want this URL pattern (/Sitemap.xml) to be sent to the S3 bucket, but rewritten to a folder (/Pilot), so the rewritten URL will be <s3-origin>/Pilot/Sitemap.xml
6 Replies
Chaika
Chaika2y ago
If you can set up your bucket on your Custom Domain proxied, you can use a simple Transform Rule Rewrite URL like this:
Chaika
Chaika2y ago
You could use dynamic rewrite concat("/pilot",http.request.uri.path) to do your ask exactly as well, but since you're only matching sitemap.xml, no real advantage of that If you are asking if you can make a specific file or host use your s3-origin directly, you can do so with Enterprise Origin Rules I believe. Otherwise, non-enterprise cannot override the host header/dns record
schlotzsky76
schlotzsky76OP2y ago
Thanks, I will use the dynamic rewrite logic, as I have other URLs that start with Sitemap that need to be coverd, so dynamic works best i do have enterprise license, but in the origin rewrite rules, it wouldn't take the s3 origin directly - I added the Host Header, but when I click save, it says either the host or port should not be empty. I think I found a solution - add a DNS record CNAME'd to the S3 and add that in the "DNS Record" Override to, but I am not sure if this is the correct approach
schlotzsky76
schlotzsky76OP2y ago
Chaika
Chaika2y ago
I believe that is the kind of setup they recommend: https://developers.cloudflare.com/rules/origin-rules/features/#dns-record As long as it works, should be fine. You can just change the URI Path to starts with /sitemap and the path rewrite to dynamic concat("/pilot", http.request.uri.path), should work without issues
schlotzsky76
schlotzsky76OP2y ago
This is helpful and I can confirm it is working. Thanks very much @chaika.me
Want results from more Discord servers?
Add your server