Custom domain should trigger worker path
Hey guys! I have a specific requirement which I couldn't find anywhere in the web or perhaps I missed it even if it is in front of me but here it goes.
I have a custom domain, say https://domain.com. I have a worker hosted and a custom path in it, say https://test.workers.dev/page1. My requirement is whenever someone goes to my custom domain, it has to trigger the worker at the said URL and return that webpage.
Any comment/help would be great. Cheers!
3 Replies
I think you could specify a
route
in your wrangler.toml
https://developers.cloudflare.com/workers/configuration/routing/routes/Routes · Cloudflare Workers docs
Routes allow users to map a URL pattern to a Worker. When a request comes in to the Cloudflare network that matches the specified URL pattern, your …
Log in to the Cloudflare dashboard.
Select Workers & Pages -> [your worker]
Select the tab Triggers
Click: "Add Custom Domain" and add domain.com
Once that's done...
Click on the Cloudflare logo to go back to the Websites section
Select domain.com
Expand "Rules" in the sidebar
Select "Transform Rules"
Click "Create rule"
Use these settings:
When incoming requests match…
URI Path -> equals -> /
Rewrite to...
Static -> page1
Click "Deploy"
That should do it.
Worked like a charm. Thanks!
@tutankhamen How about if there are two custom domains but only one should redirect?