
IIS サーバーでホストする必要がある Angular アプリの完全な URL を HTTP から HTTPS にリダイレクトする必要があります。
私は以下のルールを作成しましたが、メインドメイン(例えばhttp://www.somedomain.com、リダイレクトは問題なく行われますが、http://www.somedomain.com/route
これが私のルールです。何が間違っているのでしょうか?
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>
<rule name="Angular Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="./index.html" />
</rule>
</rules>
アイデアはリダイレクトすることですhttp://www.somedomain.com/route/somethingまたはhttp://somedomain.com/route/somethingにhttps://www.somedomain.com/route/something
答え1
同じリダイレクトを実行する方法はいくつかあります。url="https://{HTTP_HOST}/{R:1}" を使用している場合は、appendQueryString="true" を追加する必要があります。そうしないと、URI パスは追加されません。
したがって、設定は次のようになります。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
しかし、私は通常、301 リダイレクトの別のルールを使用しています。これは、状況によってはブラウザーでより適切に処理されます。このような場合は、別のタイプの URI を使用する必要があります: url="https://{HTTP_HOST}{REQUEST_URI}"
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="HTTPS force" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
答え2
正しく実行していますが、IIS には固定キャッシュがあるため、変更がすぐに反映されないことがあります。私の記憶では、iisreset を何とか乗り越えることができます。また、Google Chrome はリダイレクトを記憶するようです。
したがって、少し待つか、両方のマシンを再起動することをお勧めします(おかしいように聞こえますが)
これが私の動作構成です。同じアイデアですが、条件が異なります。
<rules>
<rule name="http to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{SERVER_PORT}" pattern="443" negate="true" />
<add input="{HTTP_HOST}" pattern="\.local$" negate="true" />
<add input="{URL}" pattern="/robots.txt" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>