简体   繁体   中英

IIS URL Rewrite + Redirect + does not match the querystring

I need to redirect to another website when the url contains www. and the query-string does not match the specfic value. I am always getting redirected irrespective of the condition

 <rewrite>
                <rules>
                    <rule name="Redirect to Landing Page" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions logicalGrouping="MatchAny">
                            <add input="{HTTP_Host}" pattern="www.dev.MyWebpage.com/MCPrivacyNotice" negate="true" />
                        </conditions>
                        <action type="Redirect" url="https://www.myWebPage.com" />
                    </rule>
                </rules>
            </rewrite>

As you described, so you need to redirect when

  • Domain is www.dev.MyWebpage.com
  • Request uri is /MCPrivacyNotice

So I think this may be your answer

    <rule name="Redirect to Landing Page" stopProcessing="true"> 
        <match url="(.*)" /> 
            <conditions logicalGrouping="MatchAll"> 
                <add input="{HTTP_HOST}" pattern="www.dev.MyWebpage.com" /> 
                <add input="{REQUEST_URI}" pattern="/MCPrivacyNotice" negate="true" /> 
            </conditions> 
        <action type="Redirect" url="myWebPage.com" /> 
    </rule>

Note that logicalGrouping="MatchAll" to match all condition. In your question and your update you used logicalGrouping="MatchAny" that means every request from domain www.dev.MyWebpage.com will be redirected

One more thing, /MCPrivacyNotice is {REQUEST_URI} or PATH_INFO not QUERY_STRING you should choose the right module. Check this for detail https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM