-1

IIS-10 in windows-server-2016 unable to redirect HTTP request to HTTPS.

I tried almost all configurations that are available over internet but still no success.

Note: My server will get sub-directory url as well and few example as like:

http://abctest.com/subfolder_1

http://abctest.com/subfolder_2

http://abctest.com

etc.

There could be N number of subfolders.), But IIS-10 unable to redirect Http request to Https.

Please find below configuration in IIS-10 GUI and also web.config file:

enter image description here enter image description here enter image description here

Community
  • 1
  • 1
Vasant
  • 101
  • 2
  • 10
  • https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/using-failed-request-tracing-to-trace-rewrite-rules – Lex Li May 27 '19 at 02:08
  • NEVER post images of code, errors or output! [mcve] – Rob May 27 '19 at 03:14
  • @LexLi , I tried Failed Request Tracing(FRT) but server request were not failing and its processing properly but it didn't redirecting http requests to https. Moreover nothing is getting created under "FailedReqLogFiles". Its really weird and not able to track why its not redirecting to https. I followed this article as well but no success: https://blogs.msdn.microsoft.com/benjaminperkins/2016/06/15/lab-4-install-and-configure-failed-request-tracing/ – Vasant May 27 '19 at 18:31

3 Answers3

1

You could use below URL rewrite rule to redirect URL with the subfolder to https:

<rule name="http to https" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTPS}" pattern="off" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" />
            </rule>

enter image description here

also, bind the certificate in site binding. if you don't have registered certificate you could bind self-signed certificate.

First, you need to create a self-signed certificate by using below Powershell command:

New-SelfSignedCertificate -DnsName www.test.com -CertStoreLocation cert:Localmachine\My

and bind that certificate with IIS site:

enter image description here

enter image description here

Regards, Jalpa

Jalpa Panchal
  • 8,251
  • 1
  • 11
  • 26
  • I tired same concept as you mentioned above long time back and even I tried again, but no success to redirection of http request to https. whenever user enters http abctest.com then always goes to http abctest.com itslef, and its not redirecting to https abctest.com request. – Vasant May 27 '19 at 18:34
  • try to remove history and cache from the browser and try again.also run failed request tracing and share detail. – Jalpa Panchal May 28 '19 at 01:16
  • Its not even loggin in Failed Request Tracing, I am suspecting it is not even going into this logic(Redirect) , looks like this is a bug in IIS10. Need to check and let me know how I can show this issue to you directly. – Vasant May 31 '19 at 00:31
1
    <rewrite>
        <rules>
            <rule name="http -> https" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
                <match url="*" />
                <conditions trackAllCaptures="true">
                    <add input="{HTTPS}" pattern="off" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}/{R:0}" redirectType="Temporary" />
            </rule>
        </rules>
    </rewrite>

Here is a working version I use for that in a production environment. Works for any binding that is tied to the site as well as with sub folders. If you don't like xml here is a screen shot of what it looks like. And then the only other thing that has caught me a time or two is make sure you have both the http and https binding of the url you are wanting to redirect.

url rewrite 1

url rewrite 2

0

I solved this by putting rules in order-wise. (Always define inbound rules in order-wise).

Thanks All of you who supported this query.

Vasant
  • 101
  • 2
  • 10