Rewrite rule on application gateway azure - 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.

Related

Azure Application Gateway Combined Path Based and Redirect rules

I want to modify my Azure Application Gwateway Path based and Redirect rules to exhibit the following behavior:
mygateway.com/test/* redirects to a website
mygateway.com/* forwards to a backend pool.
This is my current rule configuration but redirection is not occurring when I navigate to /test/*. Instead, all traffic is being routed to the /* path based rule.
Thank you!
The problem is the path based rule is being evaluated first since that is /*
everything is being sent there.
The way to fix it is to use the priority parameter to ensure that your redirect rule is evaluated first.
https://learn.microsoft.com/en-us/cli/azure/network/application-gateway/rule?view=azure-cli-latest

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.

URL redirect when accessing domain

is the first time I'm using IIS (Windows Server 2019) and I'm looking for a configuration to be able to redirect clients from http://mysiteExample.org/ to http://mysiteExample.org/embed.html?key=val. I considered that URL Rewrite Module could help me to achieve this (as is not necessary for the clients to see the new URL they'll be redirected to). I made the configuration as shown in this screenshot, where I set '^$' as a pattern to specify this should apply for cases where no URL string is provided.
Could somebody with more experience advise me on how to achieve what specified above?
Thanks in advance
I finally managed to make it work changing the action type from 'Rewrite' to 'Redirect'.

IIS URL Rewrite for a folder to another web server

I have an IIS webserver running a website. I've installed ARR3 to enable routing rules.
I'd like to redirect all the incoming request for the URL .mydomain/url2redirect/ to an Apache server installed on the same machine where is running SVN.
So in the inbound rule definition I've inserted the following:
Input: URL path after '/'
Pattern: *.mydomain/url2redirect/*
Action Type: Rewrite
Action URL: https://ip-address:8080/{R:2}
By testing the pattern, I get the desired result, and in the R:2 back reference I get the requested page I need to pass to SVN, but I get always a 404.
"url2redirect" doesn't exist but it should captured by the URL rewrite and forwarded to the Action URL.
I've added any outbound rule. Should I have to add something? what?
I've tried also to add a Reverse Proxy Rule, using the ARR template but, it's completely ignored, therefore I think that the routing is not working at all on IIS.
As far as I know, the url rewrite rule Pattern doesn't match the domain part.
That means mydomain will not include in the Pattern.
If you want to match the url2redirect, you should use below pattern.
url2redirect(.*)
Then I suggest you could modify your action url as below:
https://ip-address:8080{R:1}

Resources