Redirects using Workers - state of the art

I have read related posts, but was still wondering what’s the state of the art in doing redirects through CF Workers, in this situtation:

I moved my blog from Substack to Ghost

Currently, Substack redirects my myblog.substack.com/* to myblog.mydomain.com/* (in other words, Substack redirects to my custom domain, which then renders the posts through a Cname record).

Since I control the latter subdomain (the custom domain) on my CF, I figure I can redirect the visitor from myblog.mydomain.com/* to mydomain.com/myblog/*.

In short, a visitor to my old substack, would land, 2 redirects later to my new blog on Ghost.

Substack already does the first redirect, but I have to program the second redirect on CF Workers.

Turns out CF Workers freelancers are not easy to find. I managed to find some open source redirect code:

Lil Redirector · Built with Workers · Cloudflare Workers®

Is that the best approach and how can I find CF Workers freelancers?

I should clarify that the origin URLs and destination URLs don’t have the same slugs, so I can’t forward on the basis of some rule.

To Redirect Forward in Cloudflare Workers you use these 3 lines

const request = event.request
const url = new URL(request.url)
return Response.redirect('https://www.yourdomain.com'+url.pathname+url.search+url.hash, 301)

See URL Javascript Function

if you need split Query String
you can use

queryvars = url.search.split('&')

and then acess it via queryvars[0]

2 Likes

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