Sitecore SXA has a really nice feature of redirecting traffic from old pages to new pages (new URLS). It has (as all SXA features) really great documentation on how to set it up. In combination with Sitecore JSS (Integrated mode), you can use it also on your Sitecore JSS projects.

I have already documented on my blog, how to use this feature with regular expressions together with tokens.

Today, it will be much simpler post.

Problem

We had a requirement on the project to redirect pages ending with .html or .htm to pages coming from Sitecore.

Some of you remember good old days when all pages where just plain html / htm files. Then php came, asp, aspx, … and basically nowadays you don’t bother with nor you don’t see extensions anymore in URLs. URLs are much cleaner without exposing technology used behind.

You probably also remember signs like these on websites πŸ™‚ :

You don’t see filename or file extensions in URLs anymore. There is no need to use extensions to tell web server how to handle requests and serve it back to browser or device.

But sometimes, you still see these from time to time.

Configuration with Sitecore SXA / JSS + SXA was pretty simple with setting Redirection mapping:

But it was not working as expected.

As we have discovered, html extensions were not allowed in initial request therefore SXA was not triggering redirect as it did not recognize initial URL. It was problem already on IIS level.

We saw this nice 404 IIS message:

HTTP Error 404.0 – Not Found

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

Solution

Solution was pretty simple once I have gone through / decompiled couple of SXA dlls.

There is OOTB configuration which looks like this:

This basically allows aspx, ashx and asmx extensions to be allowed. Html extension was blocked by default.

I have created patch config file similarly to this one:

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
	<sitecore>
		<pipelines>
			<preprocessRequest>
				<processor>
					<param desc="Allowed extensions (comma separated)">aspx, ashx, asmx, html</param>
				</processor>
			</preprocessRequest>
		</pipelines>
	</sitecore>
</configuration>

Deployed it and voila, all started to work…

You can also add htm if you wish πŸ™‚

Happy Sitecoring…