title: URL Rewrite to remove www and redirect to https using web-config (c# .net)
body: <p>I have the following code in my web-config to be able to redirect both the URLs with the prefix "www" and non-SSL requests to the https:// mydomain.com because the SSL certificate is registered to the domain without the www</p>
  
  <pre><code>&lt;rewrite&gt;
    &lt;rules&gt;
      &lt;rule name="Remove WWW prefix and redirect to https" &gt;
        &lt;match url="(.*)" ignoreCase="true" /&gt;
        &lt;conditions logicalGrouping="MatchAny"&gt;
          &lt;add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" ignoreCase="true" /&gt;
          &lt;add input="{HTTPS}" pattern="off" ignoreCase="true" /&gt;
        &lt;/conditions&gt;
        &lt;action type="Redirect" redirectType="Permanent" url="https://mydomain.com/{R:1}" /&gt;
      &lt;/rule&gt;
    &lt;/rules&gt;
  &lt;/rewrite&gt;
  </code></pre>
  
  <p>This is the result:</p>
  
  <p>1) http:// mydomain.com/something --> https:// mydomain.com/something (Correct)</p>
  
  <p>2) http:// www.mydomain.com/something --> https:// mydomain.com/something (Correct)</p>
  
  <p>3) https:// www.mydomain.com/something --> Shows certificate error (There is a problem with this website's security certificate.)</p>
  
  <p>When you select "Continue to this website (not recommended)." on the certificate error page, the url is rewritten correctly (https:// mydomain.com/something)</p>
  
  <p>How can I make sure the certificate error does not show?</p>
  
  <p>Thank you</p>