簡體   English   中英

Angular 2 - 始終重定向到https://而不是使用http://

[英]Angular 2 - always redirect to https:// instead of using http://

我有一個Angular 2應用程序,我只想在https上運行。 重定向使用http的地址改為使用https的最佳方法是什么?

我已將web.config添加到Angular2站點,其中包含以下內容。 請記住,這適用於IIS托管的應用程序。 現在所有地址都重定向到https版本。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <clear />
                <rule name="Redirect to https" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

根據您的問題,您必須從服務器端強制為您的域https。 正如您在評論中提到的IIS,這里有一些方法可以實現強制HTTps。

https://www.sslshopper.com/iis7-redirect-http-to-https.html

我必須根據web api在同一區域內的位置編寫web api服務的例外規則:/

注意這一行

  <add input="{REQUEST_URI}" pattern="^/(C2NGService)" negate="true" />

web.config for angular 5

<configuration>
<system.webServer>
<rewrite>
    <rules>
    <rule name="Angular Routes" enabled="true" stopProcessing="true">
        <match url=".*" />
        <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{REQUEST_URI}" pattern="^/(C2NGService)" negate="true" />
        </conditions>
        <action type="Rewrite" url="/" />
    </rule>
    </rules>
</rewrite>
</system.webServer>
</configuration>

暫無
暫無

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

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