简体   繁体   中英

How to redirect non www or non http to https://www.example.com

I have written below rule in web.config

<rewrite>
  <rules>
    <rule name="HTTPS force" enabled="true" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="^OFF$" />
      </conditions>
      <action type="Redirect" url="https://www.example.com" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

It works well for the below url

www.example.com
http://example.com ,
http://www.example.com ,
https://www.example.com and
example.com

but not works for https://example.com . I wanted to rewrite it to https://www.example.com

what will be the required changes so it will be achieve?

I have changed my rewrite rule to this and my problem is resolved.

<rewrite>
  <rules>
    <rule name="HTTPS force" enabled="true" stopProcessing="true">
      <match url="(.*)" />
      <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
        <add input="{HTTP_HOST}" pattern="^example\.com$" />
        <add input="{SERVER_PORT}" pattern="^80$" />
      </conditions>
      <action type="Redirect" url="https://www.example.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
    </rule>
  </rules>

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