Azure API Management "rewrite url" - how to remove the URL prefix

Viewed 907

I have a large number of public URLs starting with /abc/*, for example:

/abc/user

/abc/login

/abc/group/admin

How can I rewrite the URL rule to get rid of /abc/* like this:

/user

/login

/group/admin

I tried to set the URL template to /abc/*, and rewrite template is /. It seems the url template can get to know the above urls, but the rewrite template cannot write the result I want.

enter image description here enter image description here

1 Answers

I tested with your scenario - this gives you /xxxx as forwarding path for /abc/xxxx:

<rewrite-uri template="@(context.Request.OriginalUrl.Path.Replace(context.Api.Path+"/abc",""))" copy-unmatched-params="true" />

or to do it more generic:

<rewrite-uri template="@(context.Request.OriginalUrl.Path.Replace(context.Api.Path+context.Operation.UrlTemplate.Replace("/*",""),""))" copy-unmatched-params="true" />
Related