How can I mask a url in cloudflare

how can i mask a url that is redirected to another domain

Unfortunately, you can’t.

More details here: https://developers.cloudflare.com/dns/troubleshooting/faq/#does-cloudflare-offer-domain-masking

1 Like

You can use a worker.

2 Likes

Can anyone advise further on this worker scenario, trying a fetch worker, .site1.com/ > https://site2.com/images/image1.png just a static page, while keeping the site1.com url in the browser.

I used the sample: https://developers.cloudflare.com/workers/examples/fetch-html/
Deployed this worker:

export default {
async fetch(request) {
const someHost = “`https://storage.googleapis.com`”;
const url = someHost + “/mybucket/image1.png”;

async function gatherResponse(response) {
const { headers } = response;
const contentType = headers.get(“content-type”) || “”;
if (contentType.includes(“application/json”)) {
return JSON.stringify(await response.json());
} else if (contentType.includes(“application/text”)) {
return response.text();
} else if (contentType.includes(“text/html”)) {
return response.text();
} else {
return response.text();
}
}

const init = {
headers: {
“content-type”: “text/html;charset=UTF-8”,
},
};

const response = await fetch(url, init);
const results = await gatherResponse(response);
return new Response(results, init);

},
};

I made a route rule .site1.com/ sent to worker, and the only dns record I have is an A record site1.com > 192.0.2.1 Proxied. But if I go to the site it gives a CF 522 time out error.

It looks like the problem is my contenttype is image/x-png … and I am not sure how to write the response code, it think it needs to be base64 encoded, but I am not a js developer so struggling a bit if anyone has any input.

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