2017-04-25 124 views
1

我有一個擁有ssl證書的網站。 該域名是http://example.com 我有一個子域http://api.example.com其中沒有ssl證書。Asp.net mvc 301重定向

所以我想使用web.config MVC將我的http://example.com重定向到https://example.com

當我這樣做,子域也被重定向301

我想重定向只是我的主要領域。

我的代碼如下:

<rewrite> 
     <rules> 
     <rule name="Redirect-HTTP-HTTPS-IIS"> 
      <match url="(.*)" /> 
      <conditions> 
      <add input="{HTTPS}" pattern="^OFF$" ignoreCase="true" /> 
      </conditions> 
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" /> 
     </rule> 
     </rules> 
    </rewrite> 
+0

嘗試加入另一種情況,像<添加輸入= 「{HTTP_HOST}」 模式= 「^ example.com $」 ignoreCase =「true」/> –

回答

0

試試這個

<rule name="RedirectDomain" enabled="true" stopProcessing="true"> 
     <match url=".*" /> 
     <conditions logicalGrouping="MatchAny" trackAllCaptures="true"> 
      <add input="{HTTP_HOST}" pattern="^example.com$" /> 
     </conditions> 
     <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" /> 
    </rule>