Can cloudflare map a subfolder to another website or domain (i.e. custom reverse proxy)?

Can Cloudflare map a subfolder like example.com/support to a different domain or subdomain like support.example.com or even a third party domain? I.e., can you define any custom reverse proxy rules?

This is possible within Azure Frontdoor but I can’t see that cloudflare has any similar function?

Thanks
Nick

Sure thing. Use resolve header override + host header override: Using Resolve Override in Page Rules – Cloudflare Help Center.

On an Enterprise plan you can use the Resolve Override in a Page Rule.

On other plans you can use a Worker to achieve this.

When going the Workers way, you can use the following two examples as a starting point:

  1. https://developers.cloudflare.com/workers/examples/respond-with-another-site;
  2. https://developers.cloudflare.com/workers/examples/bulk-origin-proxy.
2 Likes

Thanks. I’m not getting far with the workers approach. Why is this code invalid (it deliberately has no effect):

async function handleRequest(request) {
  // My code will go here
  return fetch(request)
}

addEventListener("fetch", async event => {
  event.respondWith(handleRequest(event.request))
})

Error:

If you did not assign this worker to any route that had an origin behind it, then you simply did not respond to these requests with anything. If you assign this worker to a working route with an origin behind it, it will work and will not yield any errors.

Having said this, hello world is a much better place to start such tests:

addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
return new Response('hello world', {status: 200})
}

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