How can I make the media library only serve up content for a files actual extension, and perform a 301 permanent redirect to the actual URL for any other extension. For SEO reasons.

By default the media library works for multiple extensions, e.g. ashx, doc, docx etc I can get the media library links to be generated with the right extension.

But I want search engines which have a link to an invalid extension to updated to the actual file extension. To prevent the same file being indexed multiple time on different paths.

If it was a web page could have a canonical URL, but for media library items, need to perform a permanent redirect to the actual file desired url/extension.

3 Answers 3


Loooong time ago I wrote a blog post describing how to handle this issue. It was for Sitecore 6.5 but I guess it should work on any other version as well.

Sitecore serves media items even with incorrect extensions

The idea is that there is an extra processor added to httpRequestBegin pipeline which checks whether the extension used in requested url is same as extension of the media item.

My solution returned 404 not found in such a scenario but you can easily change it to 301 redirect if you think it's a better idea.


I'm not sure exactly what your asking for here but if you want to show the 'real' file extension for PDFs, Docs, Images etc then I'd suggest enabling Media.RequestExtension like so:

<setting name="Media.RequestExtension" value="" /> 

To prevent duplicate urls for files you may be able to use an MediaRequestHandler as described by Martin Davies here:


  • Blog post is by Martin Davies, not me :)
    – jammykam
    Commented Feb 20, 2018 at 14:39
  • Sorry Kam, scan read the bottom bit where it mentioned you. I've updated it now. Commented Feb 21, 2018 at 22:01

You question is not very specific, though you can control extension logic via main web.config if its Sitecore version is < 8.1 or Sitecore.config if its >= 8.1 You can disable supporting ashx extensions and force to support only native extensions by altering this section: aspx, ashx, asmx and this should have value=""

In regards to MediaTypes control they are outlined all in section.

All amendments to the logic how media items are handled, you'll have to provide your own There are lots of examples on inet, it depends what exactly you want to achieve, all permanent redirections are implemented in your own MediaProvider.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.