2
votes

Related to the question Getting Sitecore 404 for physical files I was specifically tasked to remove the tilde prefix on the media folder (also mentioned in one of the answer from the question). I get 404 when opening the media library afterwards like the related question above. So I added /sitecore/shell/Applications/Media/MediaShop AND /sitecore/shell/Applications/Media/Media Folder.aspx to the IgnoreUrlPrefix setting in the web.config This fixes the issue, but i'm not sure how this fixed the problem, and why removing the tilde on the media folder causes 404 on media library page. Can someone please explain ?

1
This is how Sitecore described kb.sitecore.net/articles/723979Jan Bluemink
Are you getting the error on the backend CMS in the editor or only on the front end CD site?jammykam

1 Answers

3
votes

If you have existing content which was created when the tilde prefix was in place then that existing content in Rich Text Fields in particular still has the tilde prefix being used. You can check this by looking at the Edit HTML or Raw Values of the field, it will be in the format:

<img src="-/media/123A4B6789012CAB34C567AB79CBD084.ashx?h=100%25&w=100%25" style="height: 100%; width:100%;">

In order to change the tilde and still support the old content you need to supplement your media config changes, patch in the changes to the following sections:

<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>

    <settings>
      <!-- Extensions of media files should match it's type -->
      <setting name="Media.RequestExtension">
        <patch:attribute name="value"></patch:attribute>
      </setting>

      <!-- Change the media prefix from the default -->
      <setting name="Media.MediaLinkPrefix">
        <patch:attribute name="value">-/media</patch:attribute>
      </setting>
    </settings>

    <!-- Media handler prefixes -->
    <customHandlers>
      <handler patch:before="*[@trigger='~/media/']" trigger="-/media/" handler="sitecore_media.ashx" />
    </customHandlers>

    <!-- Support Media Prefixes -->
    <mediaLibrary>
      <mediaPrefixes>
        <prefix value="-/media"/>
        <prefix value="~/media"/>
      </mediaPrefixes>
    </mediaLibrary>

  </sitecore>
</configuration>

Change the prefixes to match whatever you need.

The link will be rendered correctly on the front end site in any case. Note, you have used /media, which media that if there is a piece of content created called media* then the media handler will try to handle it even if it is content, e.g. mysite.com/media/news or mysite.com/news/latest/media/. You may want to add some validation to prevent such items being created.