简体   繁体   中英

IIS URL Rewrite RegEx not Operating as Expected

I'm attempting to setup an IIS URL Rewrite rule to redirect all of the traffic for EXAMPLE.com to www.EXAMPLE.com unless the request is for a specific path.

I tried to modify my rewrite rule so that it would redirect all requests except for if the path includes /.well-known/acme-challenge/ ... but it's not working and it's still redirecting. I can't figure out what I'm doing wrong though:/

I've tried using both {PATH_INFO} and {REQUEST_URI} but neither works. Does negate="true" not do what I think it does??

<rule name="Redirect EXAMPLE.com to www.EXAMPLE.com" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^EXAMPLE.com$" />
        <add input="{PATH_INFO}" pattern="^.*/\.well-known/acme-challenge/.*$" negate="true" />
    </conditions>
   <action type="Redirect" url="https://www.EXAMPLE.com/{R:0}" />
</rule>

Screenshot of Inbound Rule in GUI

Running IIS v10.0.14393.0 on Windows Server 2016 v1607

Backstory (for those interested): www.EXAMPLE.com is hosted on a server that will not allow a visitor to use the caniocal domain; they must ensure that they have WWW before the URL. I don't have any ability to change that.

My workaround was to configure a URL Rewrite rule on a server I do control so that if someone attempts to go to EXAMPLE.com they will still end up at the site they are looking for. The EXAMPLE.com to www.EXAMPLE.com redirect should work regardless if the end user is connecting via HTTP or HTTPS so I was going to use Let's Encrypt to generate a TLS cert. Unfortunately that fails because the rewrite rule is successfully redirecting to the other server and the ACME verification is failing.

The rule continued not to function properly until I used Server Manager to install Tracing under Web Server (IIS) > Web Server > Health and Diagnostics.

Should this have fixed it? No clue. Doesn't seem like it should have to me. But I cannot deny that it worked. Thanks Jalpa Panchal for setting me down the right path.

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