Score:1

Problems with excluding an url from being redirected

pr flag

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.

Pimp Juice IT avatar
ch flag
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!!
PeterL avatar
pr flag
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
Lex Li avatar
vn flag
https://halfblood.pro/iis-url-rewrite-tip-break-free-adccdb4b9f2f If you add a break rule ahead then things can be just easy.
PeterL avatar
pr flag
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?
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.