【问题标题】:Sitecore Redirect module Regex Pattern MatchingSitecore 重定向模块正则表达式模式匹配
【发布时间】:2016-09-13 03:22:03
【问题描述】:

使用 Sitecore 7 的 301 重定向模块时,我在确定要在 Sitecore 重定向模块中使用的正确请求表达式和源值时遇到问题。我有一个示例 url,它通常会获取我想要重定向到网站主页的请求。

示例 url 请求都在 URL 的末尾包含 excite.com:

https://www.example.com/products/foods/apples/excite.com
https://www.example.com/products/foods/oranges/excite.com
https://www.example.com/products/foods/pears/excite.com

我希望将这些末尾包含 excite.com 的请求重定向到主页 (https://www.example.com),但我这辈子都想不通。

【问题讨论】:

  • 您使用的是哪个重定向模块?市场上有几种,它们的工作方式略有不同。
  • 我正在使用 301 重定向模块

标签: redirect sitecore sitecore7


【解决方案1】:

我没有使用过301 Redirect Module,但使用过类似的模块。有 2 个问题需要解决。

您需要使用模式匹配重定向创建重定向。您需要的正则表达式是“匹配任何以/excite.com 结尾的请求”

.*(/excite.com)$

另一个问题是 Sitecore 将 url 的 .com 部分视为扩展,然后过滤请求。您需要将com 添加到允许的扩展程序列表中。

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
      <preprocessRequest>
        <processor type="Sitecore.Pipelines.PreprocessRequest.FilterUrlExtensions, Sitecore.Kernel">
          <param desc="Allowed extensions (comma separated)">aspx, ashx, asmx, com</param>
        </processor>
      </preprocessRequest>      
    </pipelines>    
  </sitecore>
</configuration>

话虽如此,如果您使用的是 IIS 重写模块,那么您可以在其中添加一个规则,该规则将在您甚至点击 Sitecore 管道之前得到解析和重定向,因此您无需担心允许的扩展过滤器.

<rules>  
  <rule name="Redirect excite.com" stopProcessing="true">
    <match url=".*(/excite.com)$" />
    <action type="Redirect" url="https://{HTTP_HOST}" appendQueryString="false" />
  </rule>
</rules>

如果您还希望它与 http://ww.example.com/excite.com 匹配,请将正则表达式更改为 (excite.com)$|.*(/excite.com)$

【讨论】:

猜你喜欢
  • 2015-08-29
  • 2020-08-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多