簡體   English   中英

Asp.net mvc 301重定向

[英]Asp.net mvc 301 redirect

我有一個網站有ssl證書。 該域名是http://example.com我有一個子域http://api.example.com ,它沒有ssl證書。

所以我想使用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>

嘗試這個

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM