Handling URL requests with different file extensions in Sitecore

Hey there! Welcome to "Sitecore Series"

Post is all about handling URL requests with different file extensions in Sitecore. 

In Sitecore, we usually add presentation in items, but what if we want the data to be displayed from the files added in webroot with .txt, .html or any other extensions? 

Example Scenarios:

1) Displaying a security file (mysitedomainurl/security.txt)

2) Loading a custom 404 page instead of default error page when the request is handled by IIS (mysitedomainurl/404.aspx or mysitedomainurl/404.html)


Here is the solution for different scenarios:

Allowing specific extensions:

Apply patch by adding required extensions as below:


<processor type= "Sitecore.Pipelines.PreprocessRequest.FilterUrlExtensions, Sitecore.Kernel">
<param desc="Allowed extensions (comma seperated)">.txt, .html</param>
</processor>

Allowing all extensions:


<processor type= "Sitecore.Pipelines.PreprocessRequest.FilterUrlExtensions, Sitecore.Kernel">
<param desc="Allowed extensions (comma seperated)">*</param>
</processor>

Blocking specific extensions:


<processor type= "Sitecore.Pipelines.PreprocessRequest.FilterUrlExtensions, Sitecore.Kernel">
<param desc="Blocked extensions (comma seperated)">.php</param>
</processor>


Complete Patch File:


<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<preprocessRequest>
<processor type= "Sitecore.Pipelines.PreprocessRequest.FilterUrlExtensions, Sitecore.Kernel">
<param desc="Allowed extensions (comma seperated)">.txt, .html</param>
</processor>
</preprocessRequest>
</pipelines>
</sitecore>
</configuration>


Additional Info:

In case of url requests with file extensions, Sitecore will only process the requests contains allowed extensions.

All other file extension requests are redirected to default 404 error page, served by IIS. Want to know the details about redirecting it to the custom 404 page created in Sitecore in this scenario? 

Refer my post on displaying custom 404 page for un allowed file extensions in Sitecore.


Hope this post helps you. Happy Sitecoring... 😊

Comments

Popular posts from this blog

Overwriting sxa content field in solr document

Displaying Custom 404 error page for urls with unallowed file extension in sitecore

How to specify custom richtext menu as default richtext field setting when no source is specified for richtext field in sitecore

How to rebuild custom solr index programmatically in Sitecore

Rendering Parameters and Rendering Parameter Templates in Sitecore

Accessing Items from Sitecore Database in different scenarios