2016-04-27 23 views
1

我意識到這是一個簡單的問題,但我只是找不到答案。我已經應用了以下規則...http to https在IIS中

<rewrite> 
      <rules> 
      <rule name="HTTP to HTTPS redirect" stopProcessing="true"> 
       <match url="(.*)" /> 
       <conditions> 
       <add input="{HTTPS}" pattern="off" ignoreCase="true" /> 
       </conditions> 
       <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" /> 
      </rule> 
      </rules> 
     </rewrite> 

的URL我感興趣的是有圖案

http://[domain]/[directory]/[aspx page] 

所以http://example.com/funstuff/thefair.aspx

重寫的結果http://[domain]/[an_aspx_page]

所以重寫是刪除目錄。我認爲{R:1}指定了一個將被重寫的參數,並且我嘗試了https:// {HTTP_HOST}/{R:1}/{R:2},但是這會導致500錯誤。

我希望將此域中的所有流量指向https而不更改用戶輸入的其餘網址。

+1

{R:1}和{R:2}(等)表示用於匹配URL的正則表達式的捕獲組。您沒有第二個捕獲組,這就是爲什麼{R:2}未定義的原因。 http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module –

回答

2

以下是我們在其中一個網站上使用的功能,可將所有流量自動重定向到https版本。它還包含網址中的所有其他內容。

<rewrite> 
     <rules> 
      <clear /> 
      <rule name="Redirect to https" enabled="true" stopProcessing="true"> 
       <match url="(.*)" /> 
       <conditions> 
        <add input="{HTTPS}" pattern="off" ignoreCase="true" /> 
       </conditions> 
       <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="true" /> 
      </rule> 
     </rules> 
    </rewrite> 
+0

完美!謝謝。漂亮的個人資料圖片 – tintyethan