IIS URL rewrite custom server variable Bug

Markus Sc 1 Reputation point
2022-08-26T08:08:52.37+00:00

Hello,
I have a custom server variable in the IIS URL Rewrite module let's call it CUSTOMER in which I store the value of {PATH_INFO} in an inbound rule.
Because I am only interested in the part of the path identifying the customer i made an outbound rule to rewrite the variable to get only the customer part (Matching scope: Server Variable).

The full path is like:

/relay/CustomerId/Controller/Action  

my pattern is:

^/relay/([^/]+)/.*  

the rewrite rule is:

{R:1}  

which should work and I double checked it with regex101.com.

Due to the presumed bug I get the full unaltered value of the original path.
As soon as you add just any character or a second group to the rewrite rule the behavior is as expected.

So for me the workaround is that (by adding the group (.)) I changed the pattern to:

^/relay/(.)([^/]+)/.*  

with this rewrite rule:

{R:1}{R:2}  

Such a solution is not optimal and may, in certain circumstances, lead to unforeseeable erroneous behavior some time later in production. So I think this bug should be fixed.

At least I hope to help someone else facing this issue struggling with finding a solution.

Internet Information Services
{count} votes