Redirect HTTP to HTTPS in WEB.CONFIG compatible with IIS 8.5 (ASP.NET)

MC9000 picture MC9000 · Jul 4, 2016 · Viewed 16.6k times · Source

Going bonkers here. I have a rule, to redirect ALL pages from HTTP to HTTPS, that worked just fine in IIS8 but I get a 500 Internal Server Error in IIS 8.5. I figure there is some configuration I am missing, but at a loss after searching for hours and trying all kinds of different alterations of a rewrite rule in system.WebServer in the web.config file. Here is the code (one of about 5 variations - none of which work)

<rewrite>
  <rules>
    <rule name="HTTP/S to HTTPS Redirect" enabled="true" stopProcessing="true">
        <match url="(.*)" />
        <conditions logicalGrouping="MatchAny">
          <add input="{SERVER_PORT_SECURE}" pattern="^0$" />
        </conditions>
        <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

Without simply writing this in the MasterPage (which I could do, but this darn thing worked just fine until the upgrade), is there something I am missing? A configuration perhaps?

Another version that worked (on another site hosted by IIS8.5)

<rewrite>
  <rules>
    <rule name="httpsredirect" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
    </rule>
  </rules>
</rewrite>

Answer

DaveN picture DaveN · Jul 4, 2016

Looks like you forgot to install the rewriteurl module. Get it here:

http://www.iis.net/downloads/microsoft/url-rewrite