Canonical HTTP headers
Webmasters can use rel=”canonical” HTTP headers to signal the canonical URL for both HTML documents and other types of content such as PDF files. For example, perhaps you have a white paper as an HTML page and as a PDF using two URLs – example.com/white-paper.html and example.com/white-paper.pdf. SEO‘s can signal to Google that the canonical URL for the PDF download is the HTML document by using a rel=”canonical” HTTP header when the PDF file is requested.
So how do you apply it?
If you’re using ASP.net, Classic ASP or PHP web pages, here’s how:
ASP.Net C#:
<%Response.AddHeader(@”Link”,@”< http://www.yoursite.com/>; rel=””canonical”””);%>
ASP BLOCKED SCRIPT
<%Response.AddHeader “Link”,”< http://www.yoursite.com/>; rel=””canonical”””%>
PHP:
<?php header(“Link: <http://www.yoursite.com/>; rel=”canonical””);?>
When the web page is requested the server will respond with a 200 status as well as the link header telling Google that the page is a canonical of the URL specified.
Google provided another instance when this might come in handy. For example, serving the same file from multiple URLs (common if using a content distribution/delivery network). The rel=canonical HTTP header could be used to signal to Google the preferred URL.
.htaccess
All I would need to do to make this happen is add the following code to my htaccess file:
|
1
2
3
|
<FilesMatch "my-file.pdf">Header set Link '<http://www.yoursite.com>; rel="canonical"'</FilesMatch> |
Once you’ve added that to your htaccess file, you’ll want to test your header to make sure that it’s correctly.