I want to configure my website to force a www. prefix on the name, and the HTTPS protocol.

  <rewrite xdt:Transform="Insert">
      <rule name="Add WWW prefix" enabled="true">
        <match url="(.*)" ignoreCase="true" />
          <add input="{HTTP_HOST}" negate="true" pattern="^www\.(.*)$" /> <!--pattern="^www\.([.a-zA-Z0-9]+)$"/>-->
        <action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent"/>
      <rule name="Redirect to HTTPS" enabled="true" stopProcessing="true">
        <match url="(.*)" ignoreCase="true" />
          <add input="{HTTPS}" pattern="^OFF$" />
        <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />


  1. The first rule appears to be working fine.
  2. The second rule is so far untested on the live site. (Still configuring SSL.)
  3. Are there any performance considerations when applying two rules together like this? That is, must they both be applied on each request.

1 Answer 1


Redirecting twice does cause a slight performance impact, but if you are looking to use HSTS then you should use two redirects, as there are some situations where going direct from http://example.com to https://www.example.com would cause issues.

An example is the HSTS preload list, where you must:

2) Redirect from HTTP to HTTPS on the same host, if you are listening on port 80. https://hstspreload.org/

So you will need to make sure the redirect chain goes:

http://example.com -> https://example.com -> https://www.example.com


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.