jlp
jlp

Reputation: 10358

IIS7 rewrite http and http://www to https

I switched my application to https. I added system.webServer rewrite rule

<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}" />
</rule>

in my web.config

It rewrites http://mydomain.com to https://mydomain.com which is good. Bot how to make it to rewrite also http://www.mydomain.com to https://mydomain.com (without www)

Upvotes: 1

Views: 1124

Answers (1)

ub1k
ub1k

Reputation: 1674

  1. You could make a separate rule that changes the www.mydomain.com into mydomain.com

  2. You could just hardcode your http_host and instead of using {HTTP_HOST} simply put there: "mydomain.com" so

    <action type="Redirect" redirectType="Found" url="https://mydomain.com/{R:1}" />

Upvotes: 1

Related Questions