How to rewrite url in virtual service?

Istio Ingress Gateway will receive requests like the following:

I have two apps. One is api, and another one called products.

API:

http://kp.myapp.com:8080/api/v1/list-customers. // Here I use API

http://kp.myapp.com:8080/v1/list-customers // api application expects this url without api

Products APP:

http://kp.myapp.com:8080/products/v1/list-products. // product used differentiate the app as product app.

http://kp.myapp.com:8080/v1/list-products. // application expects this.

How do I setup the VirtualService to route based on the prefix api, and product respectively but forward on the url without api, or product included as the application does not expect to see api, or product in the path.

This doc may help you.