Search code examples
iishttpswindows-server

HTTP to HTTPS on domain hosted in VPS using IIS


I have a domain which has the DNS setting pointing to a VPS.

The VPS has an IIS 10 instance which hosts the simple website using html using bootstrap.

I installed an SSL certificate and added bindings for the https part.

I am able to browse the domain on http and https.

I added the following rule to the web.config:

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

However this does not seem to help. I am still able to browse on http.

I tried the following:

  1. Tried installing URL Rewrite but it looks like Windows Server 2016 and IIS 10 does not allow the installation

  2. Tried enabling Requires SSL option.

    • This shows the website in http without images but with text
    • The website is properly displayed in https

What am I missing here?


Solution

  • I was installing the wrong URL rewrite.

    This article helped me fix the problem with the right links.

    Automatic IIS redirect http to https on Windows Server 2016: https://gridscale.io/en/community/tutorials/iis-redirect-http-to-https-windows/