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
- 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. - 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.
-
To enable canonical header, navigate to SEO settings under your manage zone section and enable this option as shown on following image:
- 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 isdomain.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>
How-to
- On your origin server, edit your
htaccess
file and insert this portion of code into it:
Example of NginX configuration block:<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>
location ~ \.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|webp|html)(\.gz)?(\?.*)?$ { add_header Link "<$scheme://$http_host$request_uri>; rel=\"canonical\""; }
- Enable custom
robots.txt
option under the SEO tab and define the allowed paths for indexing. - Purge your CDN cache, or wait for cache to expire if you have a cache hit percentage to maintain.
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.
We hope this article was helpful. As always, If you have any questions or concerns about any of the topics mentioned in this article, please feel free to reach out to support - we are available 24/7 by chat or email!