简体   繁体   中英

web.config redirecting non www to www with one route exception

Hello Im having trouble configuring my web.config file with a redirect rule.

My redirect rule now is

<rule name="Redirects to www.example.com" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
    <add input="{HTTP_HOST}" pattern="^example.com$" />

</conditions>
<action type="Redirect" url="https://www.example.com/{R:0}" />

Now I want to exclude url https://example.com/some-url (and all url-s under this one) from the rule mentioned above. This rule should not redirect https://example.com/some-url to https://www.example.com/some-url .

So how do I exclude this url from the redirect rule.

Can't you just add a condition like this (note: now edited):

<add input="{REQUEST_URI}" pattern="/some-url/(.*)" negate="true" />

to the list of conditions?

Edit: and set the conditions to "MatchAll" rather than "MatchAny"

Not tested, but seems like that may work?

(Note: Edited answer as First rule was definitely wrong; current version may work but still untested)

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