After the basic setup, I forgot to set the DNS record for
soundlake.be
and www.soundlake.be
. First thought was creating a
CNAME record with soundlake.gitlab.io
like my blog.soundlake.be
. But
then, there will be different URLs for the same resources. It doesn’t
seem right. Thus, I decide to use redirection.
1. Set Up Cloudflare Worker
- Go to the Cloudflare dashboard
- Click the manu item Workers & Pages
- Click the button Create application
- Click the button Create Worker
- Put the easily recognizable name in Name field. In my case, it is “redirect2blog”.
- Click the button Deploy
- Click the button Edit code
-
Copy & paste the following code
export default { async fetch(request, env, ctx) { return Response.redirect('https://blog.soundlake.be', 301); }, };
-
Click the button Save and deploy
Now, if you go to the worker page,
https://redirect2blog.soundlake.workers.dev/
, it will redirect your
browser to https://blog.soundlake.be
2. Custom Domains for the Worker
Prerequisite: - your own domain registered on Cloudflare.
- Go to the Cloudflare dashboard
- Click the manu item Workers & Pages
- Click the name of the worker in Overview
- Go to Triggers > Custom Domains > Add Custom Domain
- Enter
soundlake.be
and click Add Custom Domain - Enter
www.soundlake.be
and click Add Custom Domain
Now, if you go to either soundlake.be
or www.soundlake.be
it
redirects you to blog.soundlake.be
.