Solved

SEO - dynamically setting the canonical link

Posted on 2011-02-20
2
701 Views
Last Modified: 2013-11-19
Hi,

I'm for some advice on how to implement a link tag in the head of my page with the "rel=canonical" setting.


the proper syntax for this link is:
       '<link rel="canonical" href="'http://www.mysite.com/my_page'"/>');

The problem that i have is that I'm using a CMS (Netsuite) and i want to set the href value dynamcailly to use the current URL. I added some javascript to do this (see below), but when i view the source, it shows the javascript, instead of the proper tag. Is there a way to set this dynamically?

<script language=javascript> 
	document.writeln('<link rel="canonical" href="' + location.href + '"/>'); 
</script>

Open in new window

0
Comment
Question by:jrattinger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

Accepted Solution

by:
Proculopsis earned 250 total points
ID: 34941024

You will need to render this statically or server-side for spiders to make any sense of it:

  <link rel="canonical" href="<%=preferredPage%>" />

I'm not too sure why you would want to substitute the same page, as this is used to specify an alternate.
0
 
LVL 75

Assisted Solution

by:Michel Plungjan
Michel Plungjan earned 250 total points
ID: 34941025
Probably not.
Set it on the server - and you have too many quotes

In PHP:

<link rel="canonical" href="<?PHP echo "http" . ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; ?>"/>
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
In this blog, I will share you some basic tips for content marketing and to rank your website on Google.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question