2015-03-31 40 views
0

我有一個TeamCity生成服務器,用於通過IIS運行的CI。我非常希望我的網域上的任何網址都被重定向到網址的HTTPS版本。HTTPS從我的域名的任何HTTP網址重定向

我跟着教程鏈接在這裏:http://www.jppinto.com/2010/03/automatically-redirect-http-requests-to-https-on-iis7-using-url-rewrite-2-0/

<system.webServer> 
     <rewrite> 
      <rules> 
      <clear />   


    <rule name="HTTP to HTTPS redirect" stopProcessing="true"> 
     <match url="(.*)" negate="true" /> 
     <conditions> 
        <add input="{HTTPS}" pattern="^OFF$" /> 
      </conditions> 
     <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" /> 
    </rule> 

    <rule name="Subdirectory HTTP to HTTPS redirect" enabled="true" patternSyntax="ECMAScript" stopProcessing="true"> 
      <match url="(^admin/.*)" /> 
      <conditions> 
       <add input="{HTTPS}" pattern="off" /> 
      </conditions> 
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" /> 
    </rule> 

     </rules>   
    </rewrite> 
</system.webServer> 

此外,這是我的web.config的當前版本下本教程後:

我真的不知道我做錯了,因爲我的域的主要網址似乎重定向到https,但許多子域名只是404,除非您明確指定HTTPS。任何幫助,將不勝感激!

回答

0

嘗試創建JavaScript協議重定向並將新處理程序綁定到所有HTTP-80(非安全)偵聽器,其中默認錯誤頁面和默認文檔是帶有Javascript重定向的靜態文件。看下面的例子,包括截圖(鏈接)。 INSECURE的默認文檔也應該是index.htm

<!DOCTYPE html><html> 
<!-- This is index.htm --> 
<head><script> 
if (window.location.protocol != "https:") { 
    window.location.protocol = "https:"; 
    window.location.reload(); 
}</head></html> 

ASP重定向解決方案:
<% Response.Redirect "https://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("URL") %>

PHP重定向解決方案:
<?php header('HTTP/1.1 302 Found'); header('Location: https://' . $_SERVER[HTTP_HOST] . $_SERVER[REQUEST_URI]); ?>

處理器配置在IIS站點:Handler config

錯誤頁面在不安全的網站: Custom error pages

+0

我將在此期間的ASP版本上工作,如果你想要PHP的話 – NikolaTeslaX 2015-03-31 14:46:39

+0

完成後,爲答案添加了ASP和PHP解決方案。他們不檢查任何東西,不要問任何問題,只是重定向,簡短而甜蜜。如果您使用其中之一,請相應地更改文件類型。 – NikolaTeslaX 2015-03-31 15:09:06

相關問題