possibility for <link rel="canonical" ...?

Permalink 1 user found helpful
Hi all,

Is there any possibility to make use of the <link rel="canonical" href=" ...-tag with the pretty URL shown?

I experienced, that links in a template (where that tag should also be placed) are not rewritten.

Any ideas?

Thx in advance,
Sven

SigmaAlphaPi
 
Remo replied on at Permalink Reply
Remo
you could try to output $c->getCollectionPath() in your header.php (in your theme)
SigmaAlphaPi replied on at Permalink Reply
SigmaAlphaPi
Thanks Remo for the fast reply. That'll do.

I also tried to google with my search phrase (C5 forum didn't show a suitable post) and found that following thread. ;)=
http://www.concrete5.org/community/forums/customizing_c5/canonical_...
Remo replied on at Permalink Reply
Remo
yeah c5 forum search isn't perfect..

I usually search like this "site:concrete5.org canoncial", works better imho

But what you found is pretty much what I've meant! His version is actually better because the url includes http etc., getCollectionPath doesn't
Remo replied on at Permalink Reply
Remo
but be careful with this, I doubt any of these two version will generate "real canonical urls". If there's some dynamic stuff in it, it probably won't work

(e.g user info block where parameter changes content)
SigmaAlphaPi replied on at Permalink Reply
SigmaAlphaPi
Okay, but I just need it to get rid of the "index.php" in URLs that Google has indexed.

I really don't know, how they got there. The page was made public with "pretty URLs on" and i cannot find any link using that format.

Thanks a lot again anyway.
Sven
synlag replied on at Permalink Reply
synlag
i recognized that issue too. When adding links to page via tiny mce, index.php is in the href="...".
If your pretty urls are working, try the solutions described athttp://www.concrete5.org/community/forums/documentation_efforts/pre...
SigmaAlphaPi replied on at Permalink Reply
SigmaAlphaPi
Hey there,

I made that out of it. I experienced, that if cID=1 (I think that's (mostly) the main page) the URL generated washttp://domainname.tld/index.php?cID=1...

Don't know why, but this works for me.

<? 
if ($c->getCollectionId() == 1)
  {
  $canonical = 'http:// domainname.tld/'; // perhaps there's a global variable for that
  }
else
  {
  $url=Loader::helper('navigation');
  $canonical=$url->getCollectionURL($c);
  }
?>
<link rel="canonical" href="<? echo $canonical; ?>" />
pinkboi replied on at Permalink Reply
pinkboi
My method is similar, but not hard-coded to a specific site:

<?
$url=Loader::helper('navigation');
$canonical=$url->getCollectionURL($c);
$canonical=preg_replace("/index.php\?cID=1$/","",$canonical);
?>
<link rel="canonical" href="<? echo $canonical; ?>" />


I suppose it'd be sturdier if we used your method, but instead of typing out the url, used the API to retrieve it.
yashvit replied on at Permalink Reply
Try this. BASE_URL constant looks like a fair solution..

<?php 
     $canonical = BASE_URL;
   if ($c->getCollectionId() != 1){
        $url=Loader::helper('navigation');
        $canonical=$url->getCollectionURL($c);
     }
  ?>
  <link rel="canonical" href="<?php echo $canonical; ?>" />
opuscambodia replied on at Permalink Reply
Thanks this works great.
However, let's say you want trailing slashes and put in the required .htaccess entries.
When visitinghttp://www.example.com/ (or you are redirected to it)
the tag is showing ashttp://www.example.com without the trailing slash.
This adds further confusion for the search bot.
trying if $canonical == the basedomain without trailing slash
then add a trailing slash
sujiraj93 replied on at Permalink Reply
Check this url to get base url and current url in concrete5

http://avenueride.com/how-to-get-concrete5-base-url-or-current-url/...