How to implement server side canonical for Google
Google recently announced that they are supporting server side implementation of the link rel=canonical tag.
Clicking around a few links from their post you get a clear idea of how the new implementation should work, and what it should look like. However nowhere do they give an example of how to actually code this on your website.
So if anyone is interested in how to add this header to an ASP.Net, Classic ASP or PHP web page here is how:
<%Response.AddHeader “Link”,”<http://www.freshegg.com/>; rel=”"canonical”"”%>
<?php header(“Link: <http://www.freshegg.com/>; rel=\”canonical\”");?>
When a request for the web page is made the response returned by the server is still a 200 status, but in addition the link header tells Google that the page is a canonical of the URL specified in the header.
Below is a screen shot showing the headers (output taken from Fiddler2) returned by an ASP.Net webpage with the above code snippet included in the source.
The important section of the header in this case is:
This extra header replaces the on page link tag – which means a number of SEO browser plug-ins and other tools to check for the canonical tag are now going to be out of date.