General Information

Because we cache copies of your website’s files on our own servers, there is a chance that you can have Search Engine Optimization (SEO) issues with duplicate content. This scenario can happen because your files are now located on at least two different URLs, your origin server and the CDN.

Canonicalization

  1. The truth is that web crawlers see your site same way you do via your web browser, you don’t see duplicate images on your pages and neither do they. However both origin and CDN images can be indexed by these crawlers, so you need to consider what paths you want to allow for indexing on the CDN side. This can be done by using our SEO settings where you can create a custom robots.txt for your zone.
  2. The aim here is to indicate the location of indexed files and to mark these files only existing on your CDN network. The domain you send to the CDN with your origin files is called a “Preferred Domain,” and it will be used to indicate to web crawlers the domain from which you want to index your CDN files. Ideally it should be your origin domain.
  3. To enable canonical header, navigate to SEO settings under your manage zone section and enable this option as shown on following image:

    canonical-header

  4. If you still want to manage canonical header on origin side, below is the example of htaccess code you should be using to send a canonical header to the CDN when origin domain is “domain.com”:

    <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|webp|html)(\.gz)?(\?.*)?$">
                <IfModule mod_rewrite.c>
                   RewriteEngine On
                   RewriteCond %{HTTPS} !=on
                   RewriteRule .* - [E=CANONICAL:http://%{HTTP_HOST}%{REQUEST_URI},NE]
                   RewriteCond %{HTTPS} =on
                   RewriteRule .* - [E=CANONICAL:https://%{HTTP_HOST}%{REQUEST_URI},NE]
                </IfModule>
                <IfModule mod_headers.c>
                   Header set Link "<%{CANONICAL}e>; rel=\"canonical\""
                </IfModule>
             </FilesMatch>

Howto

  1. On your origin server, edit your htaccess file and insert this portion of code into it:

    <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|webp|html)(\.gz)?(\?.*)?$">
             <IfModule mod_rewrite.c>
                RewriteEngine On
                RewriteCond %{HTTPS} !=on
                RewriteRule .* - [E=CANONICAL:http://%{HTTP_HOST}%{REQUEST_URI},NE]
                RewriteCond %{HTTPS} =on
                RewriteRule .* - [E=CANONICAL:https://%{HTTP_HOST}%{REQUEST_URI},NE]
             </IfModule>
             <IfModule mod_headers.c>
                Header set Link "<%{CANONICAL}e>; rel=\"canonical\""
             </IfModule>
          </FilesMatch>

    Example of NginX configuration block:

          location ~ \.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|webp|html)(\.gz)?(\?.*)?$ {
          add_header Link "<$scheme://$http_host$request_uri>; rel=\"canonical\"";
          }
          
  2. Enable custom robots.txt option under the SEO tab and define the allowed paths for indexing.
  3. Purge your CDN cache, or wait for cache to expire if you have a cache hit percentage to maintain.

Important Note

If you enable canonical headers within your MaxCDN control panel you don’t have to do the same on origin side so, you can freely ignore htaccess and nginx configuration codes.