← Back to articles

IIS redirect HTTP to HTTPS but allow Let's Encrypt

Redirecting all HTTP to HTTPS in IIS breaks Let's Encrypt's renewal challenge. Two URL Rewrite rules fix it: let .well-known through, redirect everything else.

Tedd

Let’s Encrypt makes it easy for everyone to use HTTPS. The Windows client letsencrypt-win-simple simplifies installing and updating certificate in IIS.

Using IIS URL Rewrite function you can allow Let’s Encrypt certificate retrieval/renewal and redirect all visitors to HTTPS URL of site.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
 <system.webServer>
 <rewrite>
 <rules>
 <rule name="Allow LetsEncrypt" patternSyntax="Wildcard" stopProcessing="true">
 <match url=".well-known/*" />
 <action type="None" />
 </rule>
 <rule name="Redirect HTTP to HTTPS" patternSyntax="Wildcard" stopProcessing="true">
 <match url="*" ignoreCase="false" />
 <conditions>
 <add input="{HTTPS}" pattern="off" />
 </conditions>
 <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" />
 </rule>
 </rules>
 </rewrite>
 </system.webServer>
</configuration>

Written by Tedd · Oslo, Norway

Follow the journal via RSS