I’ve deployed sveltekit app to CF pages and have setup a worker to route to the app as a subdirectory of my main domain, e.g. mydomain.com/app
I would like to now prevent direct access to the [project].pages.dev
URL.
I’ve read a previous solution by @albert to setup a bulk redirect 301 rule for the project domain (e.g. [project].pages.dev
→ mydomain.com.app
) but this creates an infinite redirect loop for my setup.
Any suggestions? I think possibly if I were able to add some header to the first redirect and then check for that header to prevent looping the redirect, that could work but not sure how I can set this up.
I was hoping a custom expression in bulk redirect might work, but I’m getting a parse error for the following:
http.request.headers[":authority"]!="mydomain.com" and http.request.full_uri in $*listname*
After using the expression builder, I think the filter I want to apply is:
(not http.host contains "mydomain.com")
, however, this still throws it into a redirect loop.
I ended up adding a custom header value to my Cloudflare worker that was handling the reverse proxy routing and then adding an expression to check for this header value. If the value doesn’t match, then redirect. I accomplished this using the expression builder in bulk redirect.
1 Like