IIS URL rewrite module HTTP to HTTPS, exclude localhost
Last Updated: 5/6/22Problem: You want to redirect HTTP requests from users to HTTP, but your sites code makes references to app folders referring to local host using HTTP. If you unbind HTTP from IIS the HTTP version of the site breaks.
Solution overview: Use the IIS URL rewrite module, but exclude localhost from the rewrite rule.
Note on downloading rewrite module:
- If you use a web search to find the rewrite module you will find this page: https://www.iis.net/downloads/microsoft/url-rewrite
- That page is confusing if you just want the rewrite module and you don't want a whole platform for adding modules to IIS later.
- Scroll down to : "Download URL Rewrite Module 2.1" to just get the module. Skip " Web Platform Installer (WebPI) " and look to the right where it says "x64 installer"
Solution - Part 1:
Follow these steps for URL rewrite for HTTP to HTTPS:
https://www.ssl.com/how-to/redirect-http-to-https-with-windows-iis-10/
Solution - Part 2:
Next add an inbould rewrite rule conditions to the HTTP to HTTPS rule. use a new condition for {REMOTE_ADDR}. Set the check type to "pattern does not match" and set the pattern to "127\.0\.0\.1"
Next add another inbould rewrite rule conditions to the HTTP to HTTPS rule. use a new condition for {REMOTE_ADDR}. Set the check type to "pattern does not match" and set the pattern to "::1"