I came across a scenario where my client wants to handle .html extensions. They want to create 301 for .html and also wanted to serve few html files as it is in our Sitecore application.
My first thought was to create .html Handle into web configuration for handle .html extension.
When I did so, I was able to handle .html extension for my 301 but was not able to serve static html files as IIS sends all .html extension to our application as we have a handler.
We cannot redirect to the same URL for static files as it will be “too many redirects” as IIS will never serve static htmls.
Then I tried to search for any pipeline if Sitecore have where it decides which extensions to serve.
I found “CheckIgnoreFlag” pipeline where Sitecore decide if it is going to serve this type of extension or not. If not, It will return false else true.
<?xml version="1.0" encoding="utf-8"?> <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/"> <pipelines> <httpRequestBegin> <processor patch:before="processor[@type='Sitecore.Pipelines.PreprocessRequest.CheckIgnoreFlag, Sitecore.Kernel']" type="[Namespace].Class, [Namespace]"/> </httpRequestBegin> </pipelines> </sitecore> </configuration>
Here we will check for any extensions. So I create 301 Redirects here and if I don’t have any 301 Redirect for the incoming URL then I check if any physical file exists for the same path if it does
I let Sitecore handle the things. Now Sitecore returns false to IIS that it cannot handle this URL.
Then IIS tries to finds that physical file and it will redirects.
If I don’t find any physical file on the same path, I redirect to our 404 page.
By this way, we are able to handle 404 for different extensions too instead of showing IIS 404 page.