1
\$\begingroup\$

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

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

Considerations:

  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.
\$\endgroup\$
1
\$\begingroup\$

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

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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