2013-04-27 112 views
0

我使用CNAME記錄爲我的Azure網站配置了自定義域。Azure網站自定義域

一切正常,除了我可以使用* .azurewebsites.net和* .com訪問我的網站。

這不是一個SEO問題,可以避免讓我在兩種情況下都得到* .com嗎?

回答

1

你可以在你的web.config文件中簡單的URL重寫規則嘗試:

<system.webServer> 
    <rewrite> 
     <rules> 
      <rule name="MyHostNameRule"> 
       <match url="(.*)" /> 
       <conditions> 
        <add input="{HTTP_HOST}" pattern="^domain\.com$" negate="true" /> 
       </conditions> 
       <action type="Redirect" url="http://domain.com/{R:1}" /> 
      </rule> 
     </rules> 
    </rewrite> 
</system.webServer> 

基本上,它說,如果請求的主機不符合指定的模式,只是把它改寫到domain.com/。 ..如果你有權訪問IIS,那麼你可以在那裏使用Url Rewrite模塊,這個代碼可以通過嚮導創建。

一個提示:在localhost:port上開發應用程序和測試時,它會重寫url。爲避免這種情況,請將此重寫規則放在Web.Release.Config中,當然也可以將您的應用程序以發佈模式部署到Azure Web站點!只需要添加xdt:轉換爲重寫元素:

<rewrite xdt:Transform="Insert">