加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式 – IIS重写规则在实时环境中不起作用

发布时间:2020-12-14 06:26:14 所属栏目:百科 来源:网络整理
导读:我有8台服务器,3台负载均衡,第4台仅用于CMS. 已为主网站添加SSL证书,但不为CMS所在的sobdomain添加SSL证书. 我编写了一条规则,应该找到任何不包含“后台”的网址,并匹配任何其他网页以将其更改为https. 这适用于regexr.com但由于某些原因不起作用 rewrite ru
我有8台服务器,3台负载均衡,第4台仅用于CMS.

已为主网站添加SSL证书,但不为CMS所在的sobdomain添加SSL证书.

我编写了一条规则,应该找到任何不包含“后台”的网址,并匹配任何其他网页以将其更改为https.

这适用于regexr.com但由于某些原因不起作用

<rewrite>
        <rules>
            <rule name="http to https" stopProcessing="true">
                <match url="(https?://(?!backoffice).*)" />
                <conditions>
                    <add input="{HTTPS}" pattern="^OFF$" />
                </conditions>
                <action type="Redirect" url="https://www.WEBSITENAME.com{R:1}" />
            </rule>
        </rules>
    </rewrite>

Url Rewriting 2.1安装在所有4台服务器上,我已经创建了一个用于https的azure设置的负载平衡.

手动转到https工作正常(与负载平衡).

附加信息:

我尝试了很多规则,包括现有的答案.我可以看到发生的事情,比如将资产作为https引入,但页面本身不会重定向.

有2个负载均衡集,一个用于端口80,另一个用于端口443.我不知道这是否是核心,或者可能是重定向未发生的潜在原因.

你的规则应该是这样的:
<rule name="http to https" stopProcessing="true">
    <match url=".*" />
    <conditions>
        <add input="{HTTPS}" pattern="^OFF$" />
        <add input="{REQUEST_URI}" pattern="/backoffice" negate="true" />
    </conditions>
    <action type="Redirect" url="https://www.WEBSITENAME.com{R:0}" />
</rule>

此规则将使用/ backoffice路径排除请求.

另外,对于混合内容的问题,您需要修复css / js / images到亲戚的路径.例:

<img src="/path/to/your/image.jpg"/>

修复混合内容的另一种方法是创建出站规则,它将更改输出HTML(将http:替换为https :):

<rewrite>

  ...

  <outboundRules>
    <rule name="Rewrite external references to use HTTPS" preCondition="IsHTML">
      <match filterByTags="Script,Link,Img,CustomTags" customTags="HTML5Tags" pattern="^http://(.*)$" />
      <action type="Rewrite" value="https://{R:1}" />
    </rule>
    <preConditions>
      <preCondition name="IsHTML">
        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
      </preCondition>
    </preConditions>
    <customTags>
      <tags name="HTML5Tags">
        <tag name="Video" attribute="src" />
      </tags>
    </customTags>
  </outboundRules>
</rewrite>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读