【问题标题】:IIS - Redirect to subfolder with maskIIS - 使用掩码重定向到子文件夹
【发布时间】:2020-04-07 02:11:18
【问题描述】:

我使用的是 IIS 10。我的网站只能通过 HTTPS 协议通过 subdomain1.domain.comsubdomain2.domain.com 访问。

我想仅在请求来自subdomain2.domain.com 时设置重写规则,其中网站应加载 URL subdomain2.domain.com/la/signin。最后一个 URL 应该被屏蔽并且不向用户显示。

我已经尝试了很多重写规则并搜索了有关 stackoverflow 的其他建议,但即使没有掩码,每个解决方案都不适合我。

这只是我最后一次不戴口罩的尝试,但我尝试了许多其他解决方案:

<rewrite>
    <rules>
       <rule name="Redirect" stopProcessing="true">
          <match url="https://subdomain2\.domain\.com$" />
          <action type="Rewrite" url="{R:0}/la/signin" appendQueryString="true" logRewrittenUrl="true" />
       </rule>
    </rules>
</rewrite>

还有什么建议吗?

【问题讨论】:

    标签: iis url-rewriting http-redirect


    【解决方案1】:

    请试试这个规则。它会将https://subdomain2.domain.com(/) 重写为 subdomain2.domain.com/la/signin。

    <rule name="Redirect" stopProcessing="true">
              <match url="(.*)" />
              <action type="Rewrite" url="la/signin" appendQueryString="true" logRewrittenUrl="true" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="subdomain2\.domain\.com" />
                            <add input="{HTTPS}" pattern="^on$" />
                            <add input="{URL}" pattern="^(/)?$" />
                        </conditions>
           </rule>
    

    【讨论】:

    • 就我而言,这条规则完全被忽略了。它不断打开页面 subdomain2.domain.com/signin (实际存在)。该应用程序是使用 Angular 制作的,您认为 Angular 路由会参与其中吗?
    • 我记得 IIS 中的 Angular 主机也依赖于 URL 重写,所以它不应该忽略该规则。你修改过订单列表吗?只需要把它放在你的其他重写规则之上。
    • 是的,我删除了另一条规则。
    • 请启用失败请求跟踪并检查您的规则是否被忽略的原因。docs.microsoft.com/en-us/iis/troubleshoot/…
    猜你喜欢
    • 2011-10-01
    • 2013-10-16
    • 2011-12-20
    • 2018-08-28
    • 1970-01-01
    • 2017-02-13
    • 1970-01-01
    • 2016-05-03
    • 2021-10-21
    相关资源
    最近更新 更多