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
If you can set up your bucket on your Custom Domain proxied, you can use a simple Transform Rule Rewrite URL like this:
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 recordThanks, 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
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 issuesThis is helpful and I can confirm it is working. Thanks very much @chaika.me