How do I get the Canonical Code to work? Any Suggestions?

Permalink 2 users found helpful
Hi everyone. First off I would like to say thanks to everyone who posts in these forums. It has been a HUGE help to me in learning how to get some coding issues with redirects and pretty url's figured out.

My question though is I am trying to eliminate the SEO issue I am having with multiple pages. I know this have been written about before since I have found a few posts about this already.

http://concrete5packages.com/concrete5_blog/canoncial-urls/...
and
http://www.concrete5.org/documentation/how-tos/developers/seo-tip-r...

Which the 2nd posting now has all my pages going to mysite.com/about, which is nice. I like it that way however when I try using the code as given in the first url which I have seen posted on many different posts, I can not get the code to work properly.

At the top of all my pages it shows this instead of the actual page name in the code for the canonical:

<link rel="canonical" href="%3C?=$canonicalURL%20?%3E">


Can anyone explain to me exactly how to get this to work? I have been racking my brain all morning and afternoon tweaking the code on the site so I can get some stuff accomplished.

Thanks for your time and I look forward to hearing from you.

votradio
 
r1digital replied on at Permalink Reply
r1digital
I looked the code from the SEO tip and it looks like it should cover the issue your getting.

Gonna try that code myself and see what happens ;)
12345j replied on at Permalink Best Answer Reply
12345j
I believe it should be
<link rel="canonical" href="%3C?=<?php echo $canonicalURL; ?>%20?%3E">
in tonys example, but I'm not sure as I've never used it.
votradio replied on at Permalink Reply
votradio
Anyhelp you guys can give I would greatly appreciate it. I know that he has it working since I can see the canonical url when I view the source code. I will try your suggestion J and see what happens. :)
votradio replied on at Permalink Reply
votradio
Thanks J that basically did the trick. I had to modify it to work properly so I changed it to

<link rel="canonical" href="<?php echo $canonicalURL; ?>">


Which seemed to do the trick. Since I have pretty URL's should I instead have the "/" at the end of my canonical?
12345j replied on at Permalink Reply
12345j
don't believe so but I'm not an seo person.
r1digital replied on at Permalink Reply
r1digital
Think I might try that as well. Thanks for the pointer ;)

Many thanks
Mat
votradio replied on at Permalink Reply
votradio
Thanks J you helped me to get in the right direction. For anyone else getting the same issue (since I am php newbee) here is the code that will work.

<? $cPath = $c->getCollectionPath();
$canonicalURL = BASE_URL;
$canonicalURL.= $cPath;
$pageIndentifierVars = array('keywords','fID','tag','productID');
$canonicalVars = array();
foreach($pageIndentifierVars as $var)
if($_REQUEST[$var]) $canonicalVars[]= $var.'='.$_REQUEST[$var];
if( count($canonicalVars) ) $canonicalURL.= '?' . join(',',$canonicalVars);
?>
<link rel="canonical" href="<?php echo $canonicalURL; ?>">


All you do is place it in the head section of your template. Thanks again J.