9

私は問題があります。で私は2IISつのポート80443(https)httpユーザーからのすべてのリクエストをにリダイレクトしたいhttps。も追加しましRewrite rule to httpsたが、ブラウザに入るhttp://localhost/siteと同じページが表示されます。ユーザーをにリダイレクトする必要がありますhttpS://localhost/site

たぶんこれは私のローカル構成のせいですか?

そして、私はを無効Require SSLにしIISます。

The rule is:
<rewrite>
  <rules>
    <rule name="HTTPS Redirect">
      <match url="(.*)" ignoreCase="false" />
      <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="false" />
      </conditions>
      <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}{REQUEST_URI}" />
    </rule>
  </rules>
</rewrite>

ありがとうございました。

4

5 に答える 5

16

以下は、すべての要求をHTTPからHTTPSにリダイレクトするために本番IIS7サイトで使用する正確なルールです。

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Redirect to HTTPS" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTPS}" pattern="^OFF$" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

あなたが投稿したものと私たちが使用するものとの間にはいくつかの小さな違いがあります。また、ローカルホストで実行しているので、VisualStudioで組み込みのWebサーバーを使用しませんか?IISの書き換えルールは処理されないと思います。

于 2012-10-23T13:44:20.377 に答える
7

これはあなたの問題ではないかもしれませんが、私は別の問題によって引き起こされた同様の大失敗を経験しました。

Require SSLを有効にしたため、サイトは継続的に403を返しました。したがって、この方法を使用するには、SSL設定->R​​equireSSLを無効にする必要があるようです。

これが誰かを助けることを願っています。

于 2013-10-05T19:12:40.773 に答える
0

また、複数のルールがある場合は、順序が重要になる可能性があります。他のルールまたはリダイレクトが実行されない前に、必ずリダイレクトルールを追加してください。

これは、ルールの順序が必要なSPAを使用している例です。

 <rules>

         // Adding this as last rule will cause it to not redirect
        <rule name="HTTP/S to HTTPS Redirect" enabled="true" stopProcessing="true">
        <match url="(.*)" />
        <conditions logicalGrouping="MatchAny">
          <add input="{SERVER_PORT_SECURE}" pattern="^0$" />
        </conditions>
        <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
        </rule>


      <rule name="static dist files" stopProcessing="true">
        <match url="^(.+)" />
        <conditions>
          <add input="{APPL_PHYSICAL_PATH}app\{R:1}" matchType="IsFile" />
        </conditions>
        <action type="Rewrite" url="/app/{R:1}" />
      </rule>
      <rule name="index.html as document root" stopProcessing="true">
        <match url="^$" />
        <action type="Rewrite" url="/app/" />
      </rule>
      <rule name="SPA Routes" 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="^/(api)" negate="true" />
        </conditions>
        <action type="Rewrite" url="/app/" />
      </rule>
    </rules>
于 2017-12-06T21:19:44.813 に答える
0

IIS8.5 リダイレクトで動作します

3つのポイント:

  1. OFFではなく一言を使う^OFF$
  2. 使用するurl="https://{HTTP_HOST}/{REQUEST_URI}"
  3. 両方が機能しているが、この場合は好ましいタイプですが、redirectType=Permanentではなく使用してくださいFoundPermanent

webconfigコード

<rewrite>
  <rules>
    <rule name="Redirect to HTTPS" 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>
于 2020-08-07T17:52:52.230 に答える
-1

これをページに追加できます。リダイレクトを強制します。

if (!Request.IsSecureConnection)
{
Uri uri = new Uri(Request.Url, Request.RawUrl);
Response.Redirect(string.Format("https://{0}{1}{2}", uri.Host.StartsWith("www.x.com") ? uri.Host : "www.x.com", uri.AbsolutePath, uri.Query));
 }

私はあなたのMVCのタグを見ました

この属性をアクションに追加します。またはコントローラー。

[RequireHttps]
于 2012-10-23T13:47:30.983 に答える