简体   繁体   中英

HTTPS www redirects in web.config

I have the following in my web.config to force https;

<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>

But I want to force the www. as well so that all of these would go to the https://www version. What I need to achieve:

http://www.domain.tld/whatever
http://(no-www)domain.tld/whatever
https://(no-www)domain.tld/whatever

Thank you.

This rule will do the following:

  • Redirect to HTTPS
  • Force www

<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="off" />
<add input="{HTTP_HOST}" pattern="^www." negate="true" />
</conditions>
<action type="Redirect" url="https://www.example.com{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>

All that you need is to change www.example.com with your domain name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM