Problem with URL rewrite on IIS 7.5

2019-09-16 18:28发布

问题:

I'm trying to use the URL Rewrite module for IIS 7.5 to redirect all HTTP requests to HTTPS for my ASP.NET website. The site works fine at the moment but forces the user to type the https:// in the address bar.

I followed the instructions in this article. Everything seems to be fine: I've tried putting the rule in the web.config and it shows up in the UI as it should; I've also done the reverse and can see the changes in the web.config when I use the UI to add the rule. I have RequireSSL unchecked for the site. Unfortunately I still just get a 404 when I try to hit the site via http://.

I've tried a few different action urls including {HTTP_HOST}/{R:1} and the one shown below.. nothing works.

<system.webServer>
  <rewrite>
    <rules>
      <rule name="Redirect to https" stopProcessing="true">
        <match url="(.*)" />
        <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
        </conditions>
        <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}"
         redirectType="SeeOther" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>

I'm fairly new to this and pretty frustrated at this point. Seems like this should be a lot easier. Any advice would be appreciated, thanks..

Reposting from ServerFault as it's been sitting unanswered for a while.

回答1:

HTTP Error 404. The requested resource is not found

Do you actually have binding for HTTP 80 port? Sounds like you do not have it (only HTTPS).

The reason I'm asking is the quoted text is the exact message that I would see if I request unknown to IIS domain (when there is no catch-all defined) or domain is not bound to the requested port.