각도와 IIS. 전체 uRL을 유지하면서 HTTPS로 리디렉션

각도와 IIS. 전체 uRL을 유지하면서 HTTPS로 리디렉션

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>

관련 정보