Wildcard requiring trailing slash in Azure API Management (APIM) - azure

In Azure API Management (APIM), I want to setup wildcards for all GET and POST operations to my backend service. I'm encountering an issue where the consumer has to specify a trailing slash in order for the request to complete.
The wildcard is specified in APIM like this:
Example, these all work:
{{endpoint}}/devices/ <-- notice trailing slash here)
{{endpoint}}/devices/12345
{{endpoint}}/devices/12345/foo
It's just the base endpoint of a resource that does not work without the trailing slash, like:
{{endpoint}}/devices
In my particular case, it doesn't seem to recognise the route without the explicit trailing slash and requires the user to authenticate.
Is there a way to accept both with/without trailing slashes?

solved it as follow :
set up a GET /{*path} wildcard operation for current api
add the following policy to the operation inbound processing:
<rewrite-uri template="{path}" copy-unmatched-params="true" />
screenshots in github post

Related

Axios adds extra slash on get request

Axios adds extra slash on get request after the domain name, https://DOMAIN_NAME//api/get, but only when accessing via the domain name, not via local IP. When accessing via ip, it works fine.
I have tried remove the slash from on the server side, but it still has double slash. I have also tried turning off caching but no success.
If you have any ideas, please write then in an answer.

How to make Azure Rules Engine make all incoming uri paths lowercase?

Currently I have tried a few different combinations.
Essentially what I need to do this this:
www.mydomain.com/mYpaTh needs to rewrite to: www.mydomain.com/mypath but it needs to do a toLowerCase for every incoming uri, essentially making the uris case insensitive. The method cannot effect query parameters or file extensions.
This needs to be done as a wildcard, not as a specific case, most examples found online have it for only one scenario, to set up as a basic url rewrite. I need it to be done as follows:
Incoming uri contains /[A-Z] then rewrite to /[a-z] - not sure if azure actually allows this. WIld cards don't seem to work for the standard subscription, but not sure if someone has made it work in some way. I was able to get this to work in AWS cloudfront using basic javascript toLowerCase method.
For example:
Azure CDN Rules Engine

How to Redirect a URL using Application Gateway with Query included and Path excluded

I am not able to successfully redirect a URL with query to another target external URL.
eg:-
Request URL:- http://example123.com/xxx/yy?path=com
Target URL:- http://example456.com/zzz/yy
Condition:-
I need to include the query string from the Request URL but not the Path.
I have tried using the path-based routing rule on the App GateWay with below configuration
Redirect rule
But after hitting save its going back to a state like this:
Rule after save
Can anyone please find us a solution ??
According to configuration-request-routing-rules (github.com) ,
Path based rule may not send path to query and only applies it to path of url.
When you create a rule, you choose between basic and path-based.
Choose basic if you want to forward all requests on the associated listener (for example, blog.contoso.com/*) to a single back-end pool.
Choose path-based if you want to route requests from specific URL paths to specific back-end pools. The path pattern is applied only to
the path of the URL, not to its query parameters.
Also see external-site | Microsoft Docs
Please check if you can try the rewriting URL path instead of redirecting which refers to this tutorial for implementation.

Rewrite rule on application gateway azure

i would like to implement a rewrite rule on my Application Gateway v2 or other way if exist on Azure.
On application gateway i setup 2 path based rule for our main site that i call mywebsite.it deployed to webapp1:
1- if i reach mywebsite.it/function* it redirect traffic correctly to webapp2;
2- if i reach from mywebsite.it/myapplication*, for example mywebsite.it/myapplication/images/xyz the application start with mywebsite.it/function*. This rule point also to webapp2;
I would like to do this for scenario 2. From mywebsite.it/myapplication/images/xyz, apply a rewrite that change only /myapplication/, for example mywebsite.it/function/images/xyz. I need to mantain the path after function/* in rewrite operation(it is not static and change every time a user make a request when they pass from mywebsite.it/myapplication* )
I tried to configure the rewrite but it didn't work:
I can't try evaluate path map, becouse in our http setting applied to path base rules(is the same becouse web app is the same), override backend path is enabled with /. Without it application didn't work.
Any help is really appreciated
Would suggest you to please set the correct value for “Pattern to match” and “URL path value” and create the require object for HTTP header rewrite as it has stated according to the below Microsoft document. As it seems you have set wrong value for “Pattern to match” and “URL path value”.
Refer this: https://learn.microsoft.com/en-us/azure/application-gateway/rewrite-http-headers-portal
The pattern to match is a regular expression. In regular expressions, the forward slash ("/") is a reserved character so it must be escaped with a backslash ("\"), so it should look like ("\/"). Use regex101.com to test your regular expression and ensure that you get a match when you expect it and no match when you do not expect it.

The reply address 'https://...' does not match the reply addresses configured for the application even though the address exists

Trying to get some more clarity on the Azure AD app registration. I have two Reply URLs:
https://example.com
https://example.com/
I'm getting the infamous reply address mismatch, one with the trailing slash and the other without.
My understanding of this was that the app would check ALL redirect URLs to see if there was a match versus just one and failing. I've seen numerous Microsoft articles with multiple domains or routes on the same entry. Why does this fail? I also noticed this morning that my first entry in the list had the slash, and when I added the one without, it automatically moved it to the top - which I thought was odd.
Appreciate any insights.
Have you checked the Reply URLs in your code? Before I also encountered the replay address mismatch problem, I found the Reply URLs missed the trailing slash in the code to result in this mismatch, and same time there was no the trailing slash in the Azure portal.

Resources