簡體   English   中英

URL重寫和Web.config

[英]URL Rewrite and Web.config

我需要從

www.domain.comhttps://domain.com
http://www.domain.comhttps://domain.com
http://domain.comhttps://domain.com
我有以下幾行代碼,它工作正常

  <system.webServer>
<rewrite>
   <rules>
    <rule name="SecureRedirect" stopProcessing="true">
        <match url="^(.*)$" />
        <conditions>
          <add input="{HTTPS}" pattern="off" />
          <add input="{HTTP_HOST}" pattern="^(www\.)?(.*)$" />

        </conditions>
        <action type="Redirect" url="https://{C:2}" redirectType="Permanent" />
      </rule>
    </rules>
  </rewrite>
  </system.webServer>

我從這里拿走

我也想從https://www.domain.com重定向到https://domain.com
我添加以下幾行

 <rule name="Remove WWW" stopProcessing="true">
        <match url="^https://www.(.*)" />

        <action type="Redirect" url="http://{R:1}"  />
      </rule>

但無法從https://www.domain.com重定向到` https://domain.com

為什么?

您是<match><action>標記之間用於HTTP重定向的conditions片段。

嘗試這個:

 <rule name="Remove WWW" stopProcessing="true">
    <match url="^(.*)$" />
        <conditions>
            <add input="{HTTP_HOST}" pattern="^https://www.domain\.com$" />
        </conditions>
    <action type="Redirect" url="http://{R:1}"  />
 </rule>

暫無
暫無

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

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