I was going through Cloudflare Rewrite rules for appending custom path for custom domains for a use case where I have customers setting up custom domain like
abc.example.com (Custom domain to set on Cloudflare)
which needs to internally point to
xyz.lorem.com/first (existing domain hosted on a server which Cloudflare needs to point to)
You cannot use Transform Rules to rewrite the host. You can only rewrite the path, the query string, or both.
To modify the hostname, you’d need Origin Rules (beta) and an Enterprise Plan.
You can always use Redirect Rules (beta). The number o available rules vary by plan type, and you’d need to upgrade plans in case you need more Redirect Rules.
It will append the path to the domain in the request sent to your origin server. So when the user visits >https://abc.example.com/ Cloudflare will send a request to https://server.host.com/example/
If not for the rewrite rule, is there another option or is it only possible with custom middleware which runs and serves the appropriate page?
You’re right, I forgot that possibility. In the case discussed in that thread, the hostname is not changed by the Transform Rule, but by another service called Cloudflare for SaaS. On top of that, a Transform Rule is used to pass (and modify, if needed) the input path to the final domain.
Notice that what was suggested was to prepend a path to the requested path by use of concat("/example", http.request.uri.path), but by using Cloudflare for SaaS the hostname would’ve also changed in the process.
I’m not familiar with Cloudflare for SaaS, but it may fit your use case, please check the documentation:
The Transform Rule limitation applies. However, the hostname is not handled by the transform rule, but by Custom Hostnames created on your account for each customer domain, under Cloudflare for SaaS.
As I said, I’m not familiar with how Cloudflare for SaaS works, but hopefully other members of this Community may be able to help you further. For that, you may prefer to open a separate topic explaining in more detail what setup you want to create, and what needs you have, besides having customer domains rewritten.