2014-03-13 91 views
1

我在Web.config文件中的條目<system.webServer>下:重定向不是重定向

<rewrite> 
    <rules> 
    <rule name="Redirect to HTTPS" stopProcessing="true"> 
     <match url="(.mydomain.com*)" /> 
     <conditions> 
     <add input="{HTTPS}" pattern="^OFF$" /> 
     </conditions> 
     <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" /> 
    </rule> 
    </rules> 
</rewrite> 

我期望這http://www.mydomain.com請求將被重定向到https://www.mydomain.com。但是,這沒有發生。

規則的格式有問題嗎?還必須做其他事情以啓用重定向嗎?

這是在IIS 8下的Windows 2012計算機上運行.RewriteModule列在該網站的模塊下。

回答

1

刪除"(.mydomain.com*)"並將其設置爲"(.*)"

<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> 
+0

更改後的行爲相同。 –

+0

@EricJ。試試這個。對不起,我以前的答案。 – rpax

+0

這樣做!任何想法,爲什麼?之前的模式也是匹配的。 –

1

確保IIS重寫模塊(可安裝使用Web Platform Installer安裝之後,你可以使用IIS管理器see, configure, and test the rewrite rules

編輯:我注意到你說你驗證模塊安裝酷最有可能的!這是一個規則本身的問題,使用IIS提供的測試工具來驗證它是否以你期望的方式工作

編輯2:我認爲你的規則的問題是你的匹配URL語法根據http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#Rule_pattern_syntax,默認語法是ECMAScript正則表達式,這意味着如果你想匹配.字符,你必須使用\.

+0

對不起,遲到已安裝RewriteModule編輯。我現在查看管理重寫規則的鏈接。 –

+0

當我輸入測試模式www.mydomain.com時,它告訴我輸入的URL與模式匹配。儘管如此,它並沒有重定向。 –