Repetitive optional parameters in route

I’ve been looking for a solution that would allow me using multiple optional parameters in a route.

Something like
/product/{category?*}/{productname}

Let’s say I have 1 product that belongs to 4 categories and a second product that belongs to 7 categories. These categories are in a parent-child relation (it’s a tree). I would like to see the whole category family in the url when I go to the product page.

For example, the first product url would look like this:

www.myshop.com/product/main1/sub1/sub11/sub111/myproduct

With the second product it would be:

www.myshop.com/product/main2/sub2/sub22/sub222/sub2222/sub22222/sub222222/myproduct2

Is there a solution that would allow behaviour like this?