Ad

Is Pushing A Canonical Link Into The Head With JavaScript Acceptable For Google

So basically I have a site where occasionally I setup a "vanity" url for web campaigns or product literature:

i.e.

http://www.example.com/campaign-URL

links to the same page as

http://www.example.com/normal-site-URL

I set this up with a rewrite in IIS7, and as such, it's difficult to grab the real URL from the underlying ASP.NET code since Context.Request.Url returns the rewritten URL instead of the URL the user visited. This makes it difficult to inject the <link rel="canonical" tag into the page at render time.

Instead, what I've done is to check the URL through JavaScript and inject the <link rel="canonical" tag that way.

Honestly, I don't think it ultimately will make much of a difference since the preferred URL is already submitted through the Google Sitemap, but since I have some SEO folks that are demanding it, I'm wondering if this will be picked up by Google or if I'm just wasting my time adding that code.

Thanks!

Ad

Answer

Google is shakey when rendering JavaScript for it's crawler. It's not 100% that it'll read things written after.

It's easier to make sure that the rel=canonical is in the template. Make sure it goes onto all of the pages, including the original. That way if it's caught on only one and Google sees duplicate content, you won't eat a penalty. There appears to be a smart filter that will attempt to file duplicates together if even one of them has a working canonical link. Again, however, it's not something to rely on!

Ad
source: stackoverflow.com
Ad