What's the best way to lowercase the incoming requests to a specific path

Hello,

I am having an issue and I tried multiple solutions here in the community but none works.

So I have a domain in Cloudflare that is proxied - **domain.com**
I have an app in a subdomain - **app.domain.com**.

In my app, I have the following URL structure app.domain.com/model/[modelnumber]. The issue I am having is that [modelnumber] can be M9G3A or m9g3a and they are different for my backend. work.

So I need requests like https://app.domain.com/model/M9G3A6 to transform to https://app.domain.com/model/m9g3a6 only when the request is for the /model path.

I tried adding a worker - https://gist.github.com/availit/3a7e33db6a91c325ce834afebdc755e6 and inside the worker settings, it works when testing. But adding the trigger *domain.com/model* will never trigger the worker. The same is for *app.domain.com/model*

I tried with a transform rule to accept all requests and transform to

lower(http.request.uri.path)

but this messes up with some scripts because some of them are case sensitive.

Any help would be appreciated.

If you add a trigger example.com/model/* and run something like

export default {
  async fetch(req) {

    const url = new URL(req.url),
          pathName = url.pathname.split('/')

    pathName[2] = pathName[2].toLowerCase()
    url.pathname = pathName.join('/')
    
    return Response.redirect(url.toString(), 301)
  }
}

This would mean example.com/model/LKJHG would redirect to example.com/model/lkjhg and example.com/model/LKJHG/002 would redirect to example.com/model/lkjh/002.

Thank you for the suggestion. I think workers themselves work, but I can’t figure out what is the “entry point” for the Worker (the Trigger). My app is on a subdomain.

The main domain is has Cloudflare NS and as I understand, this is called full setup. My subdomain has an A record which is proxied via Cloudflare (not DNS only). As I read the help center, this means that Cloudflare is able to intercept the requests (for workers to work).

My problem is that the trigger never works if the request is coming from the subdomain.

The trigger domain.com/model/* works but I need the trigger to be app.domain.com/model/*and the second doesn’t work.

Is app.domain.com configured in Cloudflare with the appropriate DNS records?

Also note the code I posted above is rubbish and doesn’t work.