iT邦幫忙

3

HTTP重新導向HTTPS問題

想當用戶打入HTTP://www.xxx.com後, 自動導向為HTTPS://www.xxx.com, 網上看了文, 試過下面方法:

  1. 使用URL REWRITE
    在ROOT下的web.config加入下文
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <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>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
  1. 安裝IIS8自帶的HTTP重新導向
    在設在指向HTTPS://www.xxx.com 及狀態碼選永久(301)

問題是以上方式在CHROME測試時, 都出現err_too_many_redirect。
但若不用, HTTP及HTTPS網頁都正常顯示。

求教高手解決方法!!

SERVER是Windows server 2012 R2

謝謝解困!

louischou iT邦新手 4 級 ‧ 2018-05-16 09:15:56 檢舉
>too_many_redirect
這表示你重新導向在https的時候也生效,所以一直在redirect
只要對http做重新導向就好
順便一提,我個人重新導向習慣寫在php程式碼中,判斷是http時轉到https
perry168 iT邦新手 2 級 ‧ 2018-05-16 10:11:43 檢舉
我有見有文教用PHP, 但不懂程式是要放哪裡。 另外, "SSL設定"要不要使用?
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

2
zivtor
iT邦新手 4 級 ‧ 2018-05-16 10:54:50

加入

<add input="{HTTPS}" pattern="on" negate="true" />

試試看

perry168 iT邦新手 2 級 ‧ 2018-05-17 14:08:00 檢舉

THX!!!

我要發表回答

立即登入回答