Rewrite wildcard domain to subdirectories in R2 bucket

Bonjour,

(please read DOMAIN as a valid domain name - no rights to post a domainname)

I’d like to rewrite wildcard subdomains in the CF dns to subdirectories on R2.
Desired result:
SUB.DOMAIN/uilorg.jpg
will be served from:
pub-a2cbc7267a154c6f8228c776b0beef42.r2.dev/SUB/uilorg.jpg

This works more or less on old school apache .htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.).domain.fr
RewriteRule ^(.
)$ DOMAIN/%1/$1 [P,NC,QSA]

Already found the 301/302 redirect with CF page rules, but this reveals the hosting url AFAIK (bad for SEO and user experience).

Trying rules → transform rules with
(http.host eq “*.DOMAIN”) static rewrite to R2DOMAIN/$1
but this give an Error 1016

Maybe I need two steps? One to redirect the subdomain to a subdirectory on the same domain and then connect the subdirectory to the R2 subdirectory?
And what need to be in the DNS? Now a wildcard cname *

Any help is welcome.
Thanks in advance.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.