Kentico Integration

In your web.config file within <system.webServer> add the following:

<rewrite>
    <outboundRules>
        <rule name="Rewrite Media to CDN" preCondition="IsHTML">
            <match filterByTags="Img" pattern="/getmedia/(.*)" />
            <action type="Rewrite" value="https://images.mysite.com/getmedia/{R:1}" />
        </rule>
        <rule name="Rewrite Media Files to CDN by path" preCondition="IsHTML">
            <match filterByTags="Img" pattern="/media/(.*)" />
            <action type="Rewrite" value="https://images.mysite.com/media/{R:1}"/>
        </rule>
    </outboundRules>
</rewrite>

Here is a link to the IIS Rewrite module documentation for more information on configuration: https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module


Images as Background

If you are using images as a background in your CSS, you will need to use the absolute path with the CNAME domain in order for it to properly optimize.

There are also plugins in the marketplace that enable this functionality as well, but they do not always support the latest version of Kentico:

  • Laughlin Kentico CDN Rewrite 1.0, which works up to Kentico version 8.2: https://devnet.kentico.com/marketplace/utilities/laughlin-kentico-cdn-rewrite-1-0
  • Kentico CDN Injector module, which works up to Kentico 6.0: https://devnet.kentico.com/marketplace/utilities/kentico-cdn-injector