1

I'm trying to set up a set of rules on my Azure Front door to redirect all requests to the root of a site to a set of language based subfolders based on the location match of the incoming request.

Doing the Geo-location part is fairly straightforward, but I'm not having much success limiting the requests to only the root of the site - or at least when I try to do so, my rules don't appear to match and I don't get the redirect I'm expecting.

Swiss Redirect Rule

I've tried setting the above conditions:

IF "Request Path" EQUAL "/"
AND IF "Remote address" "Geo Match" "Switzerland, CH"
THEN "Routing Configuration" "Redirect" "307"
                             Host: Preserve; 
                             Destination Path: Replace: "/de-ch/"

However I don't appear to be getting the redirect when requesting the root of the site from a browser based in Switzerland.

I can't find any actual examples for using the Rules Engine with either Path or matching, so I'm wondering if I should be using "Request URL" (and therefore I'll need to put the scheme and host in there, which is less than ideal as ruleset may be working with multiple front end hosts), or should what I'm doing work?

Zhaph - Ben Duguid
  • 26,785
  • 5
  • 80
  • 117
  • Looks like the important missing part of the documentation is that "Request Path" is rooted after the initial forward slash, so there is no way to use Request Path to match a request to the root of the application. – Zhaph - Ben Duguid Feb 22 '21 at 13:58

3 Answers3

2

The "Request Path" match condition appears to match on the path after the initial /, for example given a request for:

https://www.example.com/folder/page.html

The following values are used in the match conditions:

Request Path:           folder/page.html
Request URL:            https://www.example.com/page.html
Request File Extension: html
Request Filename:       page.html

I therefore had to use the Request URL condition and limit my rules to the specific domain in the request to ensure that we were only matching the root requests.

I have not tried specifying an operator of Not Any yet, although that could also be a solution (we needed more that 25 rules, which is a further limitation, so ended up using a different solution).

Zhaph - Ben Duguid
  • 26,785
  • 5
  • 80
  • 117
1

Zhaph said they have not tried the Not Any operator at the time of writing.

I've just used it and I can confirm Not Any works for matching just the root of the domain/subdomain. Definitely takes the hassle out of creating multiple match conditions on Request URL.

Sebbs
  • 26
  • 2
1

It's possible to use regex to match an empty string, which would be the path part when accessing the root. Appears to work well for both Azure FrontDoor & Application Gateway v2.

If Operator=Regex and Request Path=^$

Explanation of the regex from this answer:

By using ^$, you match the beginning of the string with ^ immediately followed by the end of the string $.

I think the problem with "Not Any" is that it doesn't match empty string as expected but rather it doesn't match anything, as per the documentation:

All operators from the standard operator list are supported. However, the Any match condition matches every request, and the Not Any match condition doesn't match any request, when used with the request path match condition.

mtone
  • 1,685
  • 15
  • 29