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

正则表达式匹配除特定路径之外的所有https URL

发布时间:2020-12-14 06:24:32 所属栏目:百科 来源:网络整理
导读:我需要一个匹配除特定路径之外的所有https网址的正则表达式. 例如 比赛 https://www.domain.com/blog https://www.domain.com 不符合 https://www.domain.com/forms/ * 这是我到目前为止: rule name="Redirect from HTTPS to HTTP excluding /forms" enable
我需要一个匹配除特定路径之外的所有https网址的正则表达式.

例如

比赛

https://www.domain.com/blog
https://www.domain.com

不符合

https://www.domain.com/forms/ *

这是我到目前为止:

<rule name="Redirect from HTTPS to HTTP excluding /forms" enabled="true" stopProcessing="true">
    <match url=".*" />
    <conditions>
        <add input="{URL}" pattern="^https://[^/]+(/(?!(forms/|forms$)).*)?$" />
    </conditions>
    <action type="Redirect" url="http://{HTTP_HOST}/{R:0}" redirectType="Permanent" />
</rule>

但它不起作用

重定向模块的工作方式,您应该只使用:
<rule name="Redirect from HTTPS to HTTP excluding /forms" stopProcessing="true">
    <match url="^forms/?" negate="true" />
    <conditions>
        <add input="{HTTPS}" pattern="^ON$" />
    </conditions>
    <action type="Redirect" url="http://{HTTP_HOST}/{R:0}" />
</rule>

仅当请求为HTTPS且路径未以表单/或表单开头时(使用negate =“true”选项),规则才会触发重定向到HTTP.
您还可以为主机添加条件以匹配www.example.com,如下所示:

<rule name="Redirect from HTTPS to HTTP excluding /forms" stopProcessing="true">
    <match url="^forms/?" negate="true" />
    <conditions>
        <add input="{HTTPS}" pattern="^ON$" />
        <add input="{HTTP_HOST}" pattern="^www.example.com$" />
    </conditions>
    <action type="Redirect" url="http://{HTTP_HOST}/{R:0}" />
</rule>

(编辑:李大同)

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

    推荐文章
      热点阅读