can I create a page rule to redirect for example domain.com/r2/ to a public domain r2 bucket?

as the message said is it posible to create a page rule redirect so when i type in that url it will automatically redirect me to my public r2 bucket url so i can download the file easier
28 Replies
Nbc66
Nbc66OP10mo ago
also when i try to acess my page rule that i set up like this *domain.dev/r2/* i cant for some reason acess that website i get a dns error on my side
Chaika
Chaika10mo ago
I mean yea you can redirect to anything. Although you're not talking about the r2.pub one right? If so, that public access domain isn't recommended for production/is rate limited You need a proxied DNS Record for the page rule to work. If you aren't going to have any real origin/web server on that hostname, you can just create AAAA @ 100:: Proxied
Nbc66
Nbc66OP10mo ago
ahh ok so thats what i need i didnt know that
Chaika
Chaika10mo ago
100:: is IPv6 Discard, basically saying if nothing in CF handles the request/returns a response, there's no external origin it should try to connect to
Nbc66
Nbc66OP10mo ago
is there some documentation on this?
Chaika
Chaika10mo ago
like this? https://developers.cloudflare.com/dns/troubleshooting/faq/#what-ip-should-i-use-for-parked-domain--redirect-only--originless-setup
What IP should I use for parked domain / redirect-only / originless setup? In the case a placeholder address is needed for “originless” setups, use the IPv6 reserved address 100:: or the IPv4 reserved address 192.0.2.0 in your Cloudflare DNS to create a proxied DNS record that can use Cloudflare Redirect Rules, Page Rules, or Cloudflare Workers.
Cloudflare Docs
General FAQ · Cloudflare DNS docs
Yes. Cloudflare offers free DNS services to customers in all plans. Note that:
Chaika
Chaika10mo ago
or you mean specifically for setting up page rules? https://developers.cloudflare.com/rules/page-rules/how-to/url-forwarding/
Nbc66
Nbc66OP10mo ago
ok i did the thing you said i still cant be redirected to the website that so i setup the url redirect like this url: domain.dev/r2/* Forwarding URL -> 301 - Permanent Redirect Enter destination URL: https://pub-<random numbers here>.r2.dev/$1 and i still cant connect to it even affter adding the dns record you specified @Chaika
Chaika
Chaika10mo ago
it's not going to be instant, there's dns cache
Nbc66
Nbc66OP10mo ago
ohh yeha should i turn on Development mode to just test it?
Chaika
Chaika10mo ago
that's just for edge http cache, not dns cache dns cache wise you have local dns cache on your device and cache on your DNS Resolver
Nbc66
Nbc66OP10mo ago
ok i flushed my dns so i just need to wait for the dns cache to be updated then
Chaika
Chaika10mo ago
although you shouldn't be using pub-r2.dev for anything production related. Use an R2 Custom Domain instead, they're free, and you could just access your files directly like yourcustomdomain.dev/filename
Nbc66
Nbc66OP10mo ago
the issue is i want to use the apex domain as my main website and just route to r2 using the domain.com/r2
Chaika
Chaika10mo ago
then you can just add r2 to a subdomain like r2.yourcustomdomain.com/hi or cdn.yourcustomdomain.com redirects aren't going to play nice if you try to link to resources in your bucket or anything like that
Nbc66
Nbc66OP10mo ago
ok so just make a cdn subdomain then
Chaika
Chaika10mo ago
That would be recommended yea
Nbc66
Nbc66OP10mo ago
and link that in the custom domain on the r2 bucket settings correct? @Chaika how could i make the subdomain tho?
Chaika
Chaika10mo ago
you don't need to make the subdomain record or anything
Nbc66
Nbc66OP10mo ago
should i also used the parked domain method?
Chaika
Chaika10mo ago
just link it under R2 settings and it'll do it for you
Chaika
Chaika10mo ago
under R2 Bucket Settings -> Custom Domains -> Connect Domain
No description
Nbc66
Nbc66OP10mo ago
ohhh my god i didnt know that ok
Chaika
Chaika10mo ago
(CF Pages, R2 Custom Domains, Worker Custom Domains, Zero Trust Public Hostnames are all like that btw, creating records for you when you add a new hostname to them)
Nbc66
Nbc66OP10mo ago
i hade no idea you could do it like that thank you ohh 1 more question not related to this did they add support for making folders in r2? @Chaika
Chaika
Chaika10mo ago
R2, like S3/Azure/most object storages, only support folders in a virtual way with a prefix you specify If you create a file like cookies/innerfoldercookie.png, the R2 dash will show "cookies" as a folder really it'll just be the object has a key of cookies/innerfoldercookie.png
Chaika
Chaika10mo ago
The R2 S3 API, like with AWS S3, allows you to specify the delimiter you want. For example / is the common one you're used to. You can specify that in a ListObjects request for example and it'll support it: https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjects.html
ListObjects - Amazon Simple Storage Service
Returns some or all (up to 1,000) of the objects in a bucket. You can use the request parameters as selection criteria to return a subset of the objects in a bucket. A 200 OK response can contain valid or invalid XML. Be sure to design your application to parse the contents of the response and handle it appropriately.
Chaika
Chaika10mo ago
You can create objects in your bucket like folder/innerfolder/file.png, and access them via https://r2.yourcustomdomain.com/folder/innerfolder/file.png, and it'll show them (by default) in the R2 dashboard as folder-like, for other tools it depends how they work If you wanted to make an "empty folder", you'd have to make a dummy file like folder/0.dummy, but there are better ways of handling that usually so I suppose the answer is it depends what you mean, R2 supports the same S3 API as normal S3 does, and in the same general way
Want results from more Discord servers?
Add your server