Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 970
MC9000 Avatar asked Jul 04 '16 06:07

MC9000


1 Answers

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

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

like image 62
DaveN Avatar answered Oct 03 '22 07:10

DaveN