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
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
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
ahh ok so thats what i need i didnt know that
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
is there some documentation on this?
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:
or you mean specifically for setting up page rules?
https://developers.cloudflare.com/rules/page-rules/how-to/url-forwarding/
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 @Chaikait's not going to be instant, there's dns cache
ohh yeha should i turn on Development mode to just test it?
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
ok i flushed my dns
so i just need to wait for the dns cache to be updated then
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
the issue is i want to use the apex domain as my main website
and just route to r2 using the domain.com/r2
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
ok so just make a cdn subdomain then
That would be recommended yea
and link that in the custom domain on the r2 bucket settings correct? @Chaika
how could i make the subdomain tho?
you don't need to make the subdomain record or anything
should i also used the parked domain method?
just link it under R2 settings and it'll do it for you
under R2 Bucket Settings -> Custom Domains -> Connect Domain
ohhh my god i didnt know that ok
(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)
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
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
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.htmlListObjects - 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.
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