I've been dealing with this for a while now and given up, and decided to see if anyone else had a similar problem before.
So, I have the URL rewrite module from Andy Cohen (using Sitecore 8.2) https://github.com/iamandycohen/UrlRewrite
In general the redirects are working fine, even for static files such as .pdf (I have added the extra configuration in web.config to read *.pdf files etc) referenced in (https://horizontal.blog/2014/12/19/sitecore-url-rewrite-module-for-static-file-extensions/)
The problem comes when trying to redirect a .pdf from the media library. If an item inside the media library is called then this event won't trigger the InboundRewriteProcessor.cs where the request kicks off the pipeline.
My media library items follow the below structure:
https://<base_url>/-/media/<site folder>/files/<filename>.pdf
A very good blog regarding this is Matt's Sitecore Art blog
https://sitecoreart.martinrayenglish.com/2016/12/implementing-3000-redirects-in-sitecore.html
Any tips on how to get the Sitecore UrlRewrite module to redirect items inside the media library
when the media url starts with -/media/ would be greatly appreciated.
By design, Sitecore maps both
-/mediaand~/mediadirectly to the media handler, therefore, requests with~/mediaprefix never reach the redirect logic implemented byInboundRewriteProcessor.cs. This is fromSitecore.config:We have encountered a similar problem as yours multiple times and found a long-term solution through implementing a custom media handler to support the desired redirect behaviour.
Here is a code example:
Once the custom redirect handler is implemented, remember to update the
web.configfile to linkSitecore.MediaRequestHandlerto it explicitly as follows: