簡體   English   中英

IIS7 URL重寫模塊規則幫助

[英]IIS7 URL Rewrite module rule help

當有人點擊我網站的根目錄時,我正在嘗試關閉HTTPS。

我想要

https://www.domain.com/ 

重定向到

http://www.domain.com/

但我也想要

https://www.domain.com/secure.aspx

或其他任何無法重定向的命名頁面。

這是我到目前為止的內容,但無法使它正常工作。 我嘗試了一千種方法,並閱讀了所有IIS文檔和示例,但是我無法提出神奇的公式。

<rule name="Redirect Root Only to Non HTTP" stopProcessing="true"> 
   <match url="\.com/$" /> 
   <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
      <add input="{HTTPS}" pattern="on" />
   </conditions>
   <action type="Redirect" url="http://www.domain.com" appendQueryString="false" redirectType="Found" />
</rule> 

我認為這是您的答案:

<rule name="Redirect to HTTPS" stopProcessing="true">
  <match url="(.*)" />
  <conditions>
    <add input="{URL}" pattern="^.*\.aspx$" ignoreCase="true" />
    <add input="{HTTPS}" pattern="^OFF$" />
  </conditions>
  <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
<rule name="Redirect to HTTP" stopProcessing="true">
  <match url="(.*)" />
  <conditions>
    <add input="{URL}" pattern="^$" />
    <add input="{HTTPS}" pattern="^ON$" />
  </conditions>
  <action type="Redirect" url="http://{HTTP_HOST}/" redirectType="Permanent" />
</rule>

除了實際模式(僅與URL路徑部分匹配,與域名不匹配)之外,您很接近.. 正確的模式是^$ ,這意味着空字符串將僅匹配域根目錄匹配,例如https://www.domain.com/

完整規則將是:

<rule name="Redirect Root to HTTP" stopProcessing="true">
    <match url="^$"/>
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTPS}" pattern="on"/>
    </conditions>
    <action type="Redirect" url="http://www.domain.com/" redirectType="Permanent"/>
</rule>

暫無
暫無

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

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