2017-02-17 192 views
4

因此,我在其他答案和其他站點中看到了此解決方案(http://www.hanselman.com/blog/HowToEnableHTTPStrictTransportSecurityHSTSInIIS7.aspx),但我不明白如何添加HSTS標頭。我認爲它有很多與此有關:「RESPONSE_Strict_Transport_Security」服務器變量用於在IIS中強制使用SSL

<match serverVariable="RESPONSE_Strict_Transport_Security" pattern=".*" /> 

有人能解釋其中「RESPONSE_Strict_Transport_Security」是哪裏來的?

全碼:

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
     <rewrite> 
      <rules> 
       <rule name="HTTP to HTTPS redirect" stopProcessing="true"> 
        <match url="(.*)" /> 
        <conditions> 
         <add input="{HTTPS}" pattern="off" ignoreCase="true" /> 
        </conditions> 
        <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" 
         redirectType="Permanent" /> 
       </rule> 
      </rules> 
      <outboundRules> 
       <rule name="Add Strict-Transport-Security when HTTPS" enabled="true"> 
        <match serverVariable="RESPONSE_Strict_Transport_Security" 
         pattern=".*" /> 
        <conditions> 
         <add input="{HTTPS}" pattern="on" ignoreCase="true" /> 
        </conditions> 
        <action type="Rewrite" value="max-age=31536000" /> 
       </rule> 
      </outboundRules> 
     </rewrite> 
    </system.webServer> 
</configuration> 

回答

0

我不能指向您在這方面的確切來源,但我可以從實驗告訴你,「RESPONSE_Strict_Transport_Security」增加了「嚴格,運輸安全頭到響應與「RESPONSE_Expect_Staple」添加「期望主頁」標題的方式完全相同。

以下兩個鏈接有一些提示,我們可以期待上述行爲,但我從來沒有找到有關這種方式的準確文檔。

https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/modifying-http-response-headers

Add custom header based on file type