使用Sitecore 7的301重定向模块,我在建立要在Sitecore重定向模块中使用的正确请求表达式和源值时遇到问题。我有一个示例网址,通常会收到我想要重定向到网站主页的请求。
示例网址请求全部包含位于网址末尾的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),但我不能为我的生活想出这一点。
答案 0 :(得分:3)
我没有使用过301 Redirect Module但是使用了类似的模块。有两个问题需要解决。
您需要使用模式匹配重定向创建重定向。您需要的正则表达式是“匹配以/excite.com
”
.*(/excite.com)$
另一个问题是Sitecore将网址的.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>
如果您还希望匹配(excite.com)$|.*(/excite.com)$
http://ww.example.com/excite.com