1

I'm retiring the legacy site http://extranet.contoso.com but there's a specific functionality that will be needed for a while still. What I'm trying to achieve is the redirection of all requests to an info page at https://contoso.com/new-extranet-info-page/, excluding requests to http://extranet.contoso.com/printdoc.aspx?ID=1234567&AccountID=vd3l1bn&UserID=Matt which should still go through without being redirected. I'm sure it's something simple and obvious but can't figure it out. This is redirecting all requests to the info page as if the negate is being ignored.

            <rule name="Redirect to new service" stopProcessing="true">
                <match url=".*" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{REQUEST_URI}" pattern="^/printdoc\.aspx(\?.*)?$" negate="true" />
                    <add input="{HTTP_HOST}" pattern="^extranet\.contoso\.com$" />
                </conditions>
                <action type="Redirect" url="https://contoso.com/new-extranet-info-page/" appendQueryString="false" />
            </rule>

The negate passes validation when I test it against /printdoc.aspx?ID=1234567&AccountID=vd3l1bn&UserID=Matt. I tried disabling any other rewrite rules present but that has no effect.

PeterL
  • 11
  • 3
  • I think you need `pattern="off" ignoreCase="true"` and then perhaps also `appendQueryString="true" redirectType="Permanent"` as per the answer posted on https://stackoverflow.com/questions/13320614/iis-url-rewrite-role-except-some-urls. You should be able to tell it to redirect everything except for the matching group of patterns and make that be more precise to the URL you want to redirect. Trivial I believe so you're almost there. Consider making that match `*UserID=Matt` or something account specific if that's what you really need. Just the Matt account. Good luck!! – Pimp Juice IT Feb 28 '23 at 23:01
  • Thanks, I saw that answer before. This is supposed to apply both to https and http so that's why there's no http(s) pattern="off". IIS doesn't seem to add ignoreCase into it even though it's checked, but even adding it manually doesn't help. appendQueryString doesn't apply here because the page I'm redirecting to is static and doesn't know what to do with the appended queries. I tried doing a plain {QUERY_STRING} negate for just the word "printdoc" too and while it validates, it too doesn't work – PeterL Feb 28 '23 at 23:43
  • https://halfblood.pro/iis-url-rewrite-tip-break-free-adccdb4b9f2f If you add a break rule ahead then things can be just easy. – Lex Li Mar 01 '23 at 01:39
  • Thanks Lex. So if I read you correctly, it should work if I separate the two inputs into individual rules and use a break in between? – PeterL Mar 01 '23 at 01:58

0 Answers0