【问题标题】:Multi part RegEx in IIS 7 URL Rewriter for outbound links用于出站链接的 IIS 7 URL 重写器中的多部分 RegEx
【发布时间】:2011-03-31 04:02:31
【问题描述】:

我一直在尝试让 IIS URL Rewrite engine 用于特定的出站 URL 情况。我正在尝试将所有 URL 小写,但符合这些条件的 URL 除外:

  • 带有哈希标记的出站链接:page.aspx#q=MixedCaseParameter
  • 已重写的出站友好 URL,包含混合大小写的产品 ID 和产品描述:/shopping/product/A12345/Mixed-Case-Product-Description
  • 使用 javascript: 在 HREF 中而不是 URL 中的出站链接:javascript:__doPostBack('control','action')

我可以做到其中的一部分,但不能在一个表达式中完成所有部分,但我无法同时获得所有三个。这是我现在拥有的:

([A-Z]+)((?:(?!app\.aspx#q).)|(?:^(?!javascript:).))

以及web.config中的设置:

<rewrite>
  <!-- other rules excluded for clarity -->
  <outboundRules rewriteBeforeCache="true">

    <rule name="Outbound lowercase" preCondition="IsHTML" enabled="true">
      <match filterByTags="A" pattern="([A-Z]+)((?:(?!app\.aspx#q).)|(?:^(?!javascript:).))" ignoreCase="false" />
      <action type="Rewrite" value="{ToLower:{R:0}}" />
    </rule>

    <!-- Example friendly outbound rewrite rule -->
    <rule name="Rewrite Product Outbound" preCondition="IsHTML" enabled="true" stopProcessing="true">
      <match filterByTags="A" pattern="product\.aspx\?cat=catalogname&amp;amp;pid=([0-9a-zA-Z\-]+)&amp;amp;pdisplayname=([0-9a-zA-Z\-]+)" ignoreCase="true" />
      <action type="Rewrite" value="/shopping/product/{R:1}/{R:2}" />
    </rule>

    <preConditions>
      <preCondition name="IsHTML" logicalGrouping="MatchAny">
        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
      </preCondition>
    </preConditions>
    <!-- Shopping Outbound Rules End -->
  </outboundRules>
</rewrite>

谢谢。

【问题讨论】:

    标签: regex iis url-rewriting


    【解决方案1】:

    这是一个正则表达式,它将匹配您不想小写的三种类型的出站 URL:

    .*?page\.aspx#q|.*?/shopping/product|^javascript:

    测试:

    page.aspx#q=MixedCaseParameter => 匹配 /shopping/product/A12345/Mixed-Case-Product-Description => 匹配 javascript:__doPostBack('control','action') => 匹配 http://google.com => 不匹配

    【讨论】:

      猜你喜欢
      • 2020-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-29
      • 2013-07-01
      • 1970-01-01
      • 2013-11-01
      • 1970-01-01
      相关资源
      最近更新 更多