14

I recently got a SSL certificate for my website and want to redirect all traffic to HTTPS. I got everything to go to https://mydomain.com but if someone enters http://mydomain.com/anotherpage it drops the other page and just takes the user to the home page.

My rule in my web.config file looks like this:

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

I also tried https://{HTTP_HOST}{REQUEST_URI} without any success. Can anyone tell me what I need to do to make the website redirect to the proper HTTPS version of the page? I have a feeling it has something to do with the pattern, but I can't seem to figure out the syntax.

4

8 に答える 8

14

これを行う方法を見つけましたが、Rewrite モジュールは必要ありません。
以下は、Windows 8(IIS 8.5)で機能しました。

  1. サイトから HTTP バインディングを削除します (HTTPS はそのままにしておきます)。
  2. 別のサイトを追加
  3. 新しいサイトに HTTP バインディングがあることを確認してください
  4. 次のように HTTP リダイレクトを構成します。

ここに画像の説明を入力

これで、すべての HTTP 要求が HTTPS サイトにリダイレクトされ、残りの URL が保持されます。

于 2014-09-26T17:12:09.837 に答える
5

次のように変更します。

<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}" />
      </rule>
   </rules>
</rewrite>
于 2013-08-02T09:08:27.017 に答える
2

R:1がフォルダーをドロップしていたのと同じ問題がありました。このように直しました。

<rule name="http to https" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
       <add input="{HTTPS}" pattern="^OFF$" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}"
            appendQueryString="false" redirectType="SeeOther" />
</rule>
于 2015-09-30T17:35:32.050 に答える
1

まだコメントできないか、AndyH の回答の下にコメントとして残します。解決策は正しかったのですが、さらに 1 つの問題がありました (Adobe の Coldfusion サーバーの使用に関連していると思われます)。私は、それに遭遇する可能性のある他の不幸な魂のために私がしなければならなかったいくつかのさらなる研究を共有したかった.

セットアップが完了すると、リダイレクトは常に次の URL で終了します。

https://xxx.xxx.com/jakarta/isapi_redirect.dll

これに対する修正は、アドビのスレッド ( https://forums.adobe.com/thread/1034854 ) で見つかりました: アプリケーション プールの設定を次のように変更する必要がありました。

実際のサイト (HTTPS バインドのみ、実際にはコードと仮想ディレクトリが含まれます) アプリケーション プールの詳細設定:Enable 32-Bit Applications : False

Http_Redirect サイト (HTTP バインディングのみ、ディレクトリのないフォルダーの空のシェルです) アプリケーション プールの詳細設定:Enable 32-Bit Applications : True


編集:クエリ文字列の保存に関連する別の詳細:

この投稿の提案ごと ( http://www.developerfusion.com/code/4678/permanent-301-redirect-with-querystring-in-iis/ )

$S$Qドメインの最後に追加し、ボックスRedirect all requests to exact destinationがチェックされていることを確認します。次に、クエリ文字列も保存します。

于 2015-04-03T19:10:03.290 に答える
0

AndyHの答えが最も簡単で最良の方法だと思います。URL 書き換えを使用すると、ユーザーを別のページにリダイレクトするコードと競合する可能性があることもわかりました。私たちの環境では IT がよく壊れていました。しかし、アンディのソリューションは完璧に機能しました。また、Andy のソリューションは、再書き込み条件の可能性についてヒットするすべての URL を調べる必要がないため、サーバーのオーバーヘッドが少なくなると思います。

于 2015-02-09T20:58:07.987 に答える