Solved

SEO - dynamically setting the canonical link

Posted on 2011-02-20
2
689 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
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Understanding mobile browsers 9 62
add a 3rd selection to sum 7 25
where is team.js? 3 23
Index on a Table 6 8
Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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 …
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

774 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