Page 2 of 2

Re: Pretty urls and duplicate content

Posted: Tue Feb 17, 2009 4:40 pm
by calguy1000
Nope, you're not dreaming
though I would suggest you disable that tag for templates that use news detail reports, or products, or company directory, etc.

Use the same technique that I use for setting the title tag in 1.5.x, as described on my blog.
http://calguy1000.com/Blogs/4/60/the-website-saga---smarty-template-madness.html

it's quite simple actually:
a) ensure process_whole_template is set to 'false' in the config.php
(remember process_whole_template=false ensures that the body is passed through smarty, before the head is... therefore you can assign variables in the body (or in any template executed in the body) and use them in the head section).

b) add a line like this into your various detail templates

Code: Select all

{assign var='nocanonical' value='1'}
c) in the head section of your page template use something like this:

Code: Select all

{if !isset($nocanonical)}
   <link rel="canonical" href="{$content_obj->GetURL()}"/>
{/if}

Re: Pretty urls and duplicate content

Posted: Sat Mar 21, 2009 8:32 am
by Sonya
I use this ugly hack in index.php to eliminate double content.

Find in index.php the line:

Code: Select all

$pageinfo = PageInfoOperations::LoadPageInfoByContentAlias($page);
and add AFTER this line

Code: Select all

if (!$matched) {
$manager =& $gCms->GetHierarchyManager();
$node =& $manager->GetNodeByAlias($page);

if (is_object($node)) {
   $content =& $node->GetContent();
   if (is_object($content))
   {
      if (!isset($params['mact']) &&
            $config['root_url'].$_SERVER['REQUEST_URI'] != $content->GetURL()) {         
		    header ("Location: ".$content->GetURL());
		    header ("HTTP/1.0 301 Moved Permanently");
                    exit;
      }
   }
}
}
This piece of code checks if the generated url of the page is equal to the called url. If there is a difference 301-redirection is made to the right address. And I do not check it if $params['mact'] is set assuming module action.

Re: Pretty urls and duplicate content

Posted: Sat Mar 21, 2009 9:57 am
by alby
Sonya wrote: I use this ugly hack in index.php to eliminate double content.
Pay attention that you have a infinite redirect loop with cmsms in a subdir.
For example:
from:
http://127.0.0.1:81/cmsms_1.5.3/index.p ... l-template
to:
http://127.0.0.1:81/cmsms_1.5.3/index.p ... l-template

I had correct this in a old post but valid for 1.5.3 (no changed here) but I don't test in all conditions ....

Alby

Re: Pretty urls and duplicate content

Posted: Sat Mar 21, 2009 1:25 pm
by Sonya
alby wrote: Pay attention that you have a infinite redirect loop with cmsms in a subdir.
.....
I had correct this in a old post but valid for 1.5.3 (no changed here) but I don't test in all conditions ....
Alby, thank you. I did not know that my hack was already corrected :) and I was not aware of this bug. Thank you for the link. I will modify my old posts in German and Russian board too, where I had added this hack first.

There is also a problem with anchor ($matched), it has to be excluded from the code or substracted before comparing and join afterwards if redirected.

Re: Pretty urls and duplicate content

Posted: Sat Mar 21, 2009 1:37 pm
by alby
Sonya wrote: There is also a problem with anchor ($matched), it has to be excluded from the code or substracted before comparing and join afterwards if redirected.
Then try with (it's UNTESTED):
$manager =& $gCms->GetHierarchyManager();
$node =& $manager->sureGetNodeById($pageinfo->content_id);
if(is_object($node))
{
$contentobj =& $node->GetContent();

//START
if( (is_object($contentobj)) && (! $matched) )
{
$root_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
if(isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS'])=='on')
{
$root_url = str_replace('http','https',$root_url);
}
if(!isset($params['mact']) && $root_url != $contentobj->GetURL())
{
header ("Location: ".$contentobj->GetURL());
header ("HTTP/1.0 301 Moved Permanently");
exit;
}
//END

}
$smarty->assign('content_obj',$contentobj);
}
Alby