How To Implement rel=”canonical” HTTP Headers

man programming at night in the dark on his laptop

Google recently announced their support for rel=”canonical” HTTP headers. This can come in handy if you see duplication of content across different file types.

It allows webmasters to assign a file a tag that references an HTML document as the real (canonical) URL. This tag will come in hand for any website that currently offers the information on their HTML web pages as a downloadable PDF. For instance, a holiday company may be offering information on Australian holidays as both an HTML page and as a downloadable brochure in PDF format:

http://www.yoursite.com/australian-holidays.html

http://www.yoursite.com/australian-holidays.pdf

In this instance, with both files serving up the same content, a sever-side canonical tag could be applied.

All very well and good, but 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 VBScript:

<%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.

Written by Alex Harvey

Alex works for Fresh Egg, an SEO and multi discipline search agency. He has an extensive background as a web developer. Alex has reently been working on a number of sites including one that sells trampolines.

SEO & Web Design Blog

Share This Post:

Share to Facebook Share to Twitter Share to LinkedIn Stumble It Share to Delicious Sphinn This Share to Email More...
Interact With This Post:
One astute comment
  1. Joydeep says:

    Hi Alex,

    Really helpful post, but can you tell me how do I implement rel="canonical" using .HTACCESS file?

    Thanks,
    Joydeep
    Joydeep recently posted: How to Verify Authorship (rel=“author”) in Google SERP

Leave a Reply

CommentLuv badge

Stay up to date - Follow us:

Click to Subscribe

Simplify your information workflow: get blog updates delivered by email -- no more than once a day.
or
click to subscribe in your newsreader

Get the SEP Newsletter

Essential search marketing news and actionable SEO tips and strategies delivered in your inbox:



Call Us Today