AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1046607
Accepted
Pablo Varela
Pablo Varela
Asked: 2020-12-18 07:07:02 +0800 CST2020-12-18 07:07:02 +0800 CST 2020-12-18 07:07:02 +0800 CST

角度和 IIS。重定向到 HTTPS,保留完整的 URL

  • 772

对于需要托管在 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

routing iis rewrite angular
  • 2 2 个回答
  • 3165 Views

2 个回答

  • Voted
  1. ADOConnection
    2020-12-18T07:45:49+08:002020-12-18T07:45:49+08:00

    你做得对,但是 IIS 有它的有线缓存,所以有时你不会立即看到更改,据我记得它以某种方式可以在 iisreset 中存活。此外,谷歌浏览器发现记住重定向。

    所以建议是稍等或重新启动两台机器(我知道听起来很疯狂)

    这是我的工作配置。相同的想法,但不同的条件。

         <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>
    
    • 0
  2. Best Answer
    Hardoman
    2020-12-18T11:39:52+08:002020-12-18T11:39:52+08:00

    有几种方法可以进行相同的重定向。如果您使用 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>
    
    • 0

相关问题

  • 无法通过 Ubuntu VPN 访问外部网络

  • 将路由永久添加到 Solaris 10

  • Quagga 套件中的 ./configure --disable-zebra 代表什么?

  • 使用特定接口进行出站连接(Ubuntu 9.04)

  • Linux TC/策略路由工具

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve