2017-09-10 30 views
0

我在IIS中設置了一個網站,並且該網站有兩個應用程序(如下面的快照所示)。IIS自動將http重定向到https以在網站中選擇應用程序

enter image description here

我必須啓用對應用程序的HTTPS。我已安裝SSL證書並設置應用程序以使用https而不是http。現在我想實現從http到https的autoredirect,僅用於測試應用程序(PersonalCornerTest)。 我使用UrlRewrite使用下面的鏈接作爲參考,

https://www.sslshopper.com/iis7-redirect-http-to-https.html(方法1) 和 https://blogs.msdn.microsoft.com/kaushal/2013/05/22/http-to-https-redirects-on-iis-7-x-and-higher/(方法1)

我用於測試應用的配置文件中的下面設置,

<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}" /> 

然而,問題是,將下面的代碼,當用戶試圖訪問使用http在測試現場後,網址,它會自動重定向到https,但是會轉到非測試網站(即PersonalCorner)而不是測試應用程序,這是令人困惑的。

任何人都可以讓我知道我在上述設置中做了什麼錯誤嗎?我只想爲測試應用程序實現autoredirect。

+0

什麼是網址格式?你的測試和非測試網站? –

+0

您是否在您的測試應用程序的web.config中添加了此規則? –

+0

網址格式爲http://example.com/PersonalCorner/(用於非測試)和http://example.com/PersonalCornerTest(用於測試網站)。所以當我輸入http://example.com/PersonalCornerTest時,它會自動重定向到https://example.com/PersonalCorner(這是非測試) –

回答

1

自己回答我的問題!

的下方配置固定的問題,

<rewrite> 
      <rules> 
       <rule name="Redirect to https" 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="false" /> 
       </rule> 
      </rules> 
     </rewrite> 

參考:How to force HTTPS using a web.config file

相關問題