1
votes

How could one go about forcing Sitecore to handle any file requests, instead of getting a 404 from the IIS. The reason being, that we want to be able to apply the URL Rewrite Module (http://github.com/ParTech/Url-Rewriter) to file requests aswell.

Example: User requests : http://sitecore.domain/randomfolder/file.pdf (which dosent exists)

But instead of getting the IIS "HTTP Error 404.0 - Not Found via StaticFile", we want Sitecore to pick up the request, and apply any rewrite rules if available, else use the Sitecore notfound page.

I've tried adding different handlers to system.webserver without success, aswell as directly modifying Handler Mappings on the IIS settings.

1

1 Answers

9
votes

I'm not sure if you should go there, because then all requests will go through Sitecore, but if you want it you can change this configuration:

<preprocessRequest>
  <processor type="Sitecore.Pipelines.PreprocessRequest.FilterUrlExtensions, Sitecore.Kernel">
    <param desc="Allowed extensions (comma separated)">aspx</param>
    <param desc="Blocked extensions (comma separated)">*</param>
    <param desc="Blocked extensions that stream files (comma separated)">css,js</param>
    <param desc="Blocked extensions that do not stream files (comma separated)">*</param>
  </processor>
</preprocessRequest>

Set allowed extensions to * and set blocked extensions to empty (not tested).
If you know which extensions you are going to redirect (e.g. just PDF files), then only define those in the allowed extensions setting (I would suggest you do this).

<param desc="Allowed extensions (comma separated)">aspx,pdf</param>

I think that is the only thing needed for the request to be handled by the URL Rewriter module.
Keep in mind that it's untested and unsupported for file requests to be handled by that module, but in theory it should work.