2015-01-04 79 views
1

我想確保所有.net流量去我的.com,所以我創建了這個規則,但我相信我做這個錯誤,因爲它不是工作:azure網站重寫規則在web.config重定向.net到.com

<rule name=".net to .com" enabled="true" stopProcessing="true"> 
     <match url=".*mywebsite.net.*"/> 
     <action type="Redirect" url="https://mywebsite.com/" appendQueryString="false" redirectType="Permanent" /> 
     </rule> 

我認爲我有這個正則表達式正確寫的,但正則表達式是不是我的強項

回答

1

沒有您的正則表達式的問題,但這不是一般它如何規範域名規則(是什麼你想在這種情況下)成立。一般而言,您想匹配進入您的服務器的URL,然後篩選CGI環境變量的值(在這種情況下,HTTP_HOST)。您的重寫規則會是這個樣子:

<rule name="CanonicalHostNameRule1" stopProcessing="true"> 
    <match url="(.*)" /> 
    <conditions> 
     <add input="{HTTP_HOST}" pattern="^mywebsite\.com$" negate="true" /> 
    </conditions> 
    <action type="Redirect" url="https://mywebsite.com/{R:1}" appendQueryString="false" redirectType="Permanent" /> 
</rule> 

這將完成是前進,以便在不http://mywebsite.comhttps://mywebsite.comhttps://mywebsite.com網址的所有請求。實際的URL在比賽中被捕獲並且放入參數{R:1}中 - 這樣,如果你去說http://www.mywebsite.net/home.php,它將被重定向到https://mywebsite.com/home.php

另外,如果要強制HTTPS,您可以執行以下操作:

<rule name="CanonicalHostNameRule1" stopProcessing="true"> 
    <match url="(.*)" /> 
    <conditions logicalGrouping="MatchAny"> 
     <add input="{HTTPS}" pattern="^on$" negate="true" /> 
     <add input="{HTTP_HOST}" pattern="^mywebsite\.com$" negate="true" /> 
    </conditions> 
    <action type="Redirect" url="https://mywebsite.com/{R:1}" appendQueryString="false" redirectType="Permanent" /> 
</rule> 

第一個條件將檢查是否cgi.HTTPS爲「開」 ......如果它不是,重定向到一個HTTPS網址。

注:如果要重定向只mywebsite.net網址,則該情況可能是這樣的:

<add input="{HTTP_HOST}" pattern="mywebsite\.net$" /> 

希望這有助於。