1

I have setup a website in IIS and this website has two applications (as shown in the snapshot below).

enter image description here

I have to enable https on the applications. I have installed the SSL certificate and setup the applications to use https instead of http. Now I want to implement autoredirect from http to https, ONLY for the test application (PersonalCornerTest). I am using UrlRewrite using the below links as reference,

https://www.sslshopper.com/iis7-redirect-http-to-https.html (Method 1) and https://blogs.msdn.microsoft.com/kaushal/2013/05/22/http-to-https-redirects-on-iis-7-x-and-higher/ (Method 1)

I used the below setting in configuration file of the test application,

 <rule name="HTTP to HTTPS redirect" stopProcessing="true">
  <match url="(.*)" />
    <conditions>
      <add input="{HTTPS}" pattern="off" ignoreCase="true" />
    </conditions>
  <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />

However, the issue is, after adding the below code, when user tries to access the test site using http in url, it automatically redirects to https, but to the non-test site (i.e. PersonalCorner) and not the test application, which is confusing.

Can anyone let me know what mistake I am doing in the above setting? I want to implement autoredirect only for the test application.

stack underflow
  • 197
  • 2
  • 5
  • 18

1 Answers1

3

Answering my query myself!

The below configuration fixed the issue,

<rewrite>
            <rules>
                <rule name="Redirect to https" stopProcessing="true">
                    <match url=".*" />
                    <conditions>
                        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
                </rule>
            </rules>
        </rewrite>

Reference: How to force HTTPS using a web.config file

stack underflow
  • 197
  • 2
  • 5
  • 18