I've been banging my head against a brick wall attempting to get some IIS redirect rules to work. I've searched and read stuff here on Stack Overflow and on IIS.net but it just doesn't work at all.
I'm trying it on my local (real) IIS, I have the rewrite 2.0 module installed and have tried doing a repair install on it. I've done an iisreset at an admin cmd line more times than I care to mention.
In my hosts file I have set-up 127.0.0.1 for the URL my.test.com.
What I want to achieve is given a sub-domain URL redirect to the main domain URL with an extra querystring parameter whilst maintaining the existing path and querystring values if they exist.
I setup 3 rules as follows that are in the root folder of the website:
<system.webServer><rewrite><rules><rule name="PathAndQueryString" enabled="true" stopProcessing="true"><match url="(/\w*)(\?\w*=\w*)([&\w*=\w*]*)" /><action type="Redirect" url="https://www.test.com{R:1}{R:2}{R:3}&param=value" appendQueryString="false" /><conditions logicalGrouping="MatchAll" trackAllCaptures="false"><add input="{HTTP_HOST}" pattern="my.test.com" /></conditions></rule><rule name="Querstring" enabled="true" stopProcessing="true"><match url="(\?\w*=\w*)([&\w*=\w*]*)" /><action type="Redirect" url="https://www.test.com{R:1}{R:2}&param=value" appendQueryString="false" /><conditions><add input="{HTTP_HOST}" pattern="my.test.com" /></conditions></rule><rule name="DomainOnly" enabled="true" stopProcessing="true"><match url=".*" /><action type="Redirect" url="https://www.test.com?param=value" appendQueryString="false" /><conditions><add input="{HTTP_HOST}" pattern="my.test.com" /></conditions></rule></rules></rewrite></system.webServer>
Unfortunately despite testing the patterns and confirming the {R:x} captures are correct when I try to test this using Edge, Chrome, Firefox and IE for all of them IIS acts like the rules don't exist.
Tests:
- https://my.test.com>> https://www.test.com?param=value
- https://my.test.com/SomePath>>https://www.test.com/SomePath
- https://my.test.com/SomePath?AParam=AValue>>https://www.test.com/SomePath?AParam=AValue¶m=value
None of the above tests work, they get served without a redirect.
I've also tried putting the condition pattern used as part of the Match URL pattern but it didn't work with that either; in fact I moved it to the condition after reading a Stack Overflow post which said when rules are in the root of the site it doesn't include the host, but still nothing works.
Any help would be much appreciated.
UPDATE 1: For the path and querystring rule tried removing the bolded part from that start of this pattern (/\w*). Didn't have any effect.
UPDATE 2: Tried enabling the extremely temperamental "Failed Request Tracing" functionality and when it is actually working it says that none of the Match URL patterns are matching, except for the 3rd rule which has now started kicking in and redirecting but is not maintaining the path and other querystring params for obvious reasons.
UPDATE 3: On Edge and IE none of the rules work at all. On Chrome and FF the domain only redirect appears to be working - however if I disable the domain only rule and restart IIS it acts as though the rule is still there - FFS give me strength this crap is really starting to boil my blood now - this should not be that damn difficult.