My aim was three-fold
- to use a domain name in the address bar without www
- to auto-redirect from HTTP to HTTPS without fail or issue or the need to accept certificates in the browser of any kind
- simple failsafe security. if google can do it why can I?
The idea of using a 'smoky' port in the previous post was smart. While using port 80 I was constantly getting the blue IIS welcome page and the http protocol. The fake port seems to force the asp.net web page to actually read the redirection code in the web config. I changed all my http bindings to port 81. Added to that the rewrite url codes in the web.config shown below.
Another important thing to test is turning OFF the 'Required SSL' as one post indicated it may conflict with IIS Rewrite URL (any conflict that doesn't show an error can be a major headache). Prior to turning the IIS 'SSL Settings' 'Required' switch off and leaving just 'Ignore' as checked ANY combination of Rewrite URL from the hundreds of posts or walkthrough setups seemed to fail (eg this was specific to IIS10 Win 2016 but probably the same all previous IIS's).
It was also important during testing to ensure requests are outside your Lan if hosting from a Static IP. Just use your mobile hotspot and a number of browsers from your tablet (eg samsung, brave, mozilla, edge etc) to see responses of each. Part of the reason for this was based on the implementation of TLS1.2 and disabling of ALL other protocols and ciphers.
Finally don't forget to constantly delete cookies / history prior to testing page loads. In some cases a 'wipe cache partition' on an android removes any temporary files that may be causing an issue with the device (especially during testing).
This issue can be a nightmare as things that are supposed to work absolutely don't work, even though the logic is 'bulletproof logical'.
Even with all these things considered and tested, there is a good chance it won't work in some browsers... it just refuses to move from the
h*tp://domain.com
IIS welcome page... eg edge, brave, etc
Sa sample rewrite with 3 rules, as per instructions from a popular ssl site
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect www" stopProcessing="true">
<match url="www.domain.com"/>
<conditions>
<add input="{HTTPS}" pattern="^OFF$"/>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent"/>
</rule>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="domain.com"/>
<conditions>
<add input="{HTTPS}" pattern="^OFF$"/>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent"/>
</rule>
<rule name="Redirect Canonical HTTP to HTTPS" stopProcessing="true">
<match url="domain.com"/>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}"/>
</rule>
</rules>
<outboundRules>
<rule name="Add Strict-Transport-Security when HTTPS" enabled="true">
<match serverVariable="RESPONSE_Strict_Transport_Security" pattern=".*"/>
<conditions>
<add input="{HTTPS}" pattern="on" ignoreCase="true"/>
</conditions>
<action type="Rewrite" value="max-age=31536000; includeSubDomains; preload"/>
</rule>
</outboundRules>
</rewrite>
even some page load code in C# asp.net may do nothing... but it was worth a try... maybe it is not possible in IIS land.
protected void Application_BeginRequest(Object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;
if (!context.Request.IsSecureConnection)
{
UriBuilder secureUrl = new UriBuilder(context.Request.Url);
secureUrl.Scheme = "https";
secureUrl.Port = 443;
context.Response.Redirect(secureUrl.ToString(), false);
}
}