簡體   English   中英

網址重寫-Web.config-HTTPS和www

[英]Url Rewrite - Web.config - HTTPS and www

我需要能夠重定向到HTTPS(當前正在工作)和www(如果它不在URL中)。

如果網址具備www ,然后正常工作。 但是,當URL DOES具有www ,它將重定向並添加其他www ,例如https://www.www.domain.com

請注意,我不想對域進行硬編碼,而是想使用HTTPHOST或類似的東西。

當前的重寫規則:

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

最終得到此正則表達式- ^((?!www).)*[a-zA-Z0-9]+$

我還必須進入IIS,並將“與模式不匹配”​​更改為“與模式匹配”

    <rule name="Redirect to HTTPS" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="^OFF$" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
    </rule>
    <rule name="WWW Rewrite" enabled="true" stopProcessing="true">
      <match url="(.*)" />
      <conditions logicalGrouping="MatchAny">
        <add input="{HTTP_HOST}" pattern="^((?!www).)*[a-zA-Z0-9]+$" />
      </conditions>
      <action type="Redirect" url="https://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" />
    </rule>

暫無
暫無

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

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