Table lookup with matching start?

Hi,

on may way of migrating 301 redirects from F5 BigIP to Fastly, I’ve got stuck on one thing. Ive have my redirects paths in a lookup table (the sam way as in BigIP), and i would like to use table.lookup in order to find the matching start of the key in the table.

In BigIP it looks like this:

        set n [class match -element $full_path starts_with key_from_table ]

What I would like to achieve:
With a table like this:

table redirects {
   "/some/path/" : "/destination"
   "/some/other/" : "/goal*"
}

I want to be able to match and redirect several combinations like

GET /some/path/  to /destination
GET /some/path/additional  to /destination
GET /some/path/additional/segment  to /destination

And if there is a tailing *, in addition, I would need to keep additional path segments:

GET /some/other/  to /goal
GET /some/other/additional  to /goal/additional
GET /some/other/additional/segment  to /goal/additional/segment

What is the best way to achieve this?

Hi @strawberry

There’s an example solution on the Fastly Developer Hub, which might help you:

NOTE: The ‘init’ tab contains the example table and a couple of other custom subroutines.