Mfusiki Mfusiki - 2 months ago 22
ASP.NET (C#) Question

Intelligencia.UrlRewriter check domain to redirect to https

I'm having a problem trying to force https on my website while excluding locahost
I'm currently using Intelligencia.UrlRewriter to rewrite any urls and I have the following rule set up:

<if header="HTTPS" match="^OFF$">
<redirect url="(.*)" to="$1" />

This redirects fine, but I would like to make sure that my localhost debugging is not affected. This obviously runs under a different URL. So I tried:

<if header="HTTPS" match="^OFF$">
<redirect url="(.*)mydomain" to="$1" />

This however does not work. I believe the reason for that might be that it only evaluates anything after the .com.
I have tried searching for documentation with no luck.

How can I always force https connection except on my localhost?


I managed to find a solution to my problem:

<unless header="HTTP_HOST" match="localhost">
  <if header="HTTPS" match="^OFF$">
    <redirect url="(.*)" to="$1" />

With the addition of the <unless header="HTTP_HOST" match="localhost"> tag I can exclude certain hosts and still allow other hosts to be redirected to https. In other words:

This will be forced:

To (note the s in https):

But this will not be changed: