How can we rewrite the url in virtual service. eg:
Actual url----> http//test.com/service1/v1/list
rewrite url path---->/v1/list
After matching the path based routing with prefix "service1", I want to remove the second value of the url, in this case "service1" and send rest of the path(/v1/list) to the destination service.
i have tried the below VS, but it didnt worked,
spec:
hosts:
- test.com
http:
- match:
- uri:
prefix: /service1
rewrite:
uriRegexRewrite:
match: /service1(/|$)(.*)
rewrite: $2
route:
- destination:
host: service1.default.svc.cluster.local
Are there any mistakes in the "match" and "rewrite" methods for eliminating the second value from the URL while keeping the other values?
Based on the information provided, you may try this approach:
This example uses the prefix to match requests starting with /service1 and then rewrite the URI to /v1/list which is a fit for your use case.