Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SEO - dynamically setting the canonical link

Posted on 2011-02-20
2
Medium Priority
?
732 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 1000 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 1000 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

Technology Partners: 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

This article discusses how to implement server side field validation and display customized error messages to the client.
Read on to get a few ideas on how to promote your next corporate event.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
An overview of how to create reports in Adobe Analytics (formerly Omniture Site Catalyst) using pageNames, events, eVars and props. This video will show you how to install the Omniture Debugger tool so can see (and test) what is being passed int…

610 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