Sitecore Redirect module Regex Pattern Matching

北慕城南 提交于 2019-12-24 07:49:49

问题


Using the 301 Redirect Module for Sitecore 7, I'm having a problem establishing the proper Requested Expression and Source values to use in the Sitecore Redirect Module. I have an example url that is typically getting request that I want redirected to the home page of the site.

The example url requests all contain excite.com at the end of the URL:

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

I would like these requests that contain excite.com at the end to be redirected to the home page (https://www.example.com) but I can't for the life of me figure this out.


回答1:


I haven't used the 301 Redirect Module but have used similar modules. There are 2 issues that need resolving.

You need to create a redirect using the Pattern Match Redirect. The regex you need is "match any request that ends with /excite.com"

.*(/excite.com)$

The other issue is that Sitecore is seeing the .com part of the url as an extension and then filtering the request. You need to add com to the list of Allowed extensions.

<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>

All that said, if you are using the IIS Rewrite module then you could just add a rule in there which will get resolved and redirect before you even hit the Sitecore pipelines and therefore you do not need to worry about the allowed extensions filter.

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

Change the regex to (excite.com)$|.*(/excite.com)$ if you also want it to match http://ww.example.com/excite.com



来源:https://stackoverflow.com/questions/39461738/sitecore-redirect-module-regex-pattern-matching

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!