Sunday, April 29, 2018

Require HTTPS or SSL with URL Rewrite

Back in 2016, I was trying to get an IIS app to run locally

I got this error:
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.

I removed the content of the web.config inside the root node. I added them back in a section at a time. It was the node that caused the error.

I had to install https://www.iis.net/downloads/microsoft/url-rewrite
on my Windows 7 machine. Then the error went away.

Here is an example what to put in the node of your web.config

<rewrite>
<rules>
<clear />
<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>
view raw web.config hosted with ❤ by GitHub