http-redirectsitecoresitecore7

Sitecore Redirect module Regex Pattern Matching


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.


Solution

  • 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