URL Rewrite rule to redirect http to https except localhost IIS 8.6

I have run into an issue recently where I was not able to redirect https://localhost to the site.  The issue ended up being that I specified a Host name in the site bindings and it prevented https://localhost from being able to access the site.  To fix the issue leave the below Host name blank.

site bindings https localhost

To redirect http to https you have to do the following:
1.  Install the URL rewrite module on the server that’s running IIS, new icon will show up under Administrative tools > IIS Manager > IIS > URL Rewrite
http://www.iis.net/downloads/microsoft/url-rewrite
2.  You will need to create the following file if you have never created any rewrite rules.
C:\inetpub\wwwroot\web.conf
3.  Paste the below info into the file

<?xml version=”1.0″ encoding=”UTF-8″?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name=”Redirect HTTP to HTTPS” enabled=”true” stopProcessing=”true”>
<match url=”^(.*)$” />
<conditions>
<add input=”{HTTPS}” pattern=”^OFF$” />
<add input=”{HTTP_HOST}” matchType=”Pattern” pattern=”^localhost$” negate=”true” />
</conditions>
<action type=”Redirect” url=”https://{HTTP_HOST}/{R:1}” redirectType=”SeeOther” />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

4.  Go back into the URL Rewrite module and you should see the following rule that just got created.
Server1-2016-06-22-16-11-51

This entry was posted in Microsoft and tagged , , , . Bookmark the permalink.

One Response to URL Rewrite rule to redirect http to https except localhost IIS 8.6

  1. Mat J. says:

    I went over this web site and I believe you have a lot of superb information, bookmarked (:.

Leave a Reply

Your email address will not be published. Required fields are marked *