簡體   English   中英

IIS 使用 https 將 www 重定向到非 www

[英]IIS redirect www to non www using https

我需要一些幫助來實現重定向。

我得到的結果如下:

http://example.com - https://example.com   : works
http://www.example.com - https://example.com   : works
https://www.example.com - https://example.com   : doesn't work

我的配置文件:

<rule name="RedirectWwwToNonWww" stopProcessing="false">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
                    </conditions>
                    <action type="Redirect" url="https://{C:2}{REQUEST_URI}" redirectType="Permanent" />
                </rule>
                <rule name="HTTP Redirect to HTTPS" enabled="true" stopProcessing="true">
                    <match url="(.*)" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{HTTPS}" pattern="off" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
                </rule>

你可以試試這個規則:

<rule name="Force non-WWW" enabled="true" stopProcessing="true">
  <match url="(.*)" />
    <conditions logicalGrouping="MatchAny">
      <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
    </conditions>
  <action type="Redirect" url="https://{C:2}/{R:1}" appendQueryString="true" />
</rule>
<rule name="Force HTTPS" enabled="true" stopProcessing="true">
  <match url="(.*)" />
    <conditions logicalGrouping="MatchAny">
      <add input="{HTTPS}" pattern="off" />
    </conditions>
  <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" />
</rule>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM