Redirect Old URLs having extensions in URL using Sitecore SXA Redirect Mapping Module

Share:
In this article we will covert the following questions:
  • Redirect Old URLs have. (dot) extension in Sitecore SXA
  • Redirect Old URLs that don't have extensions in the URL
  • 301 Redirect Module isn't working for URL with the dot file name
  • Handling dot(.) in 301 URLs with Sitecore SXA Redirects
Recently for one of our project  we were adding 301 Redirects in Sitecore that is based on SXA, created SXA Redirect map Item based on "Redirect Map" template and starting adding the URLs(old and new URLs mapping).

When we tried to check the redirection we observed that URLs that have .htm extension Sitecore not processing that specific extension.

I searched many Sitecore official documents articles of MVPs where they are achieving their requirement by adding a rule in web.config file as following.

Simply create a rule to remove the extension from URL.
I implemented it on my locall machine and checkd that its working good but redirecting URL A to B to C. It means an extra redirection as following:.

Example:
1: /loans.htm (Old URL)
2nd: /loans (This redirection is from configuration where we are removing extension form URL)
3rd: /personal-banking/loans (New URL)

Now my requirement is to redirect URL A driectly from A to C.
I came to know that there is a preposser in Sitecore where we can allow extension based URLs for redirection.

First smply add the old and news URLs as described in below official Sitecore document : https://doc.sitecore.com/en/users/sxa/17/sitecore-experience-accelerator/map-a-url-redirect.html

You can find that all URL that does not have any extension in URL is working fine as expected except for those URL that have extension in the URL.

The issue is the request is not being processed by Sitecore, since it is seeing .old extensions such as .htm or .html as a file extension and it has not been configured as an allowed extension. You need to add all the extensions that you want to be processed since the module works integrate with the Sitecore pipelines:








Note: 
1st: Sitecore redirects mapping redirects only those URLs that are redirecting user to 404 pages.
2nd: If the old URL has any of the default allowed extensions (aspx, ashx, asmx) 

You can add more extensions to the list in the file: Sitecore.XA.Foundation.SitecoreExtensions.config 
Path: App_Config\Modules\SXA\Foundation\

Or 

Simply create a patch file with any meaningful name. We are going to name as "zzzSitecore.XA.Foundation.SitecoreExtensions.config" and put it in the include directory
Path: \App_Config\Include/zzzSitecore.XA.Foundation.SitecoreExtensions.config

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <preprocessRequest>
        <processor>
          <param desc="Allowed extensions (comma separated)">aspx, ashx, asmx, htm</param>
        </processor>
      </preprocessRequest>
    </pipelines>
  </sitecore>
</configuration>



Hi! I am Sartaj Husain. I am a Professional Software Developer, live in Delhi. I write blogs in my free time. I love to learn and share the knowledge with others because it is no good to try to stop knowledge from going forward. So free posts and tutorials. more..

No comments