Run function on specific URL

Hello, I’d like to be able to run a cloud function on a specific url.

So for example I created a cloud function that runs here;

http://localhost:8888/.netlify/functions/redirect

This function has some logic in it that redirects the user to another URL. So far so good.

I need to change this so that when the user hits /foo/somepage (for example) the function can run and perform the redirect the same as before.

I expect there will be hundreds of different URL’s I want to run this one function on (we’ve changed out site structure a bit so we need to restore some broken links that are dynamic).

Does this make sense and can you help/make suggestions? Thanks

You can use try using _redirects like this: /foo/* /.netlify/functions/redirect 200!. Read more here: Redirects and rewrites | Netlify Docs