A very simple plugin for wordpress that were made because I and my clients have had trouble with CDN and subdomains that shows html pages, and more content. which of course generate double content and the wrong pages gets indexed in Google despite of canonical URL. This plugin 301 redirect users and search engines to the correct domain.
In addition to this plugin, you need to configure your CDN such that it can not download files from the main domain, but from another subdomain. One example might be that instead of
domain.com write
dc.domain.com as the origin domain.
A working example can be found on
http://kim-tetzlaff.dk - just try to change
kim-tetzlaff.dk to
cdn.kim-tetzlaff.dk