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
2.  You will need to create the following file if you have never created any rewrite rules.
3.  Paste the below info into the file

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

4.  Go back into the URL Rewrite module and you should see the following rule that just got created.

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 *