Dynamic URL Rewriting for my websites

Hi,
I’m about the “rewrite” and create more readable URLS for my websites. But, Im a bit unsure if Cloudflare actually can handle this for me, or I need another solution for this.

As my “old” sites, an URL of mine would be:
https://www.website.com/showpainting.asp?id=74839

But instead I want it to display say:
https://www.website.dk/artistname/paintingname

So, depending on what the dynamic id=xxx would be, then I would need to look up in the database (or some XML which I could create) to get the dynamic readable URL

So, is this do-able with Cloudflare some smart way?

Start with the bulk redirects workers example (https://developers.cloudflare.com/workers/examples/bulk-redirects/).

Use Workers KV where key is the old id and value is is the new path.

Read the id from the URL e.g.

// more code...
const requestURL = new URL(request.url);
const paintingId = requestURL.searchParams.get('id')
// mode code...

The look up the KV

// more code...
const value = await env.KV.get(paintingId)
// more code...

Much like the example, redirect if value is defined, or fetch if not.

1 Like

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