Pretty urls and duplicate content

Help with getting the CMS CORE package up and running. This does not include 3rd party modules, PHP scripts, anything downloaded via module manager or from any external source.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Pretty urls and duplicate content

Post 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}
Last edited by calguy1000 on Tue Feb 17, 2009 4:43 pm, edited 1 time in total.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Sonya

Re: Pretty urls and duplicate content

Post 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.
alby

Re: Pretty urls and duplicate content

Post 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
Sonya

Re: Pretty urls and duplicate content

Post 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.
Last edited by Sonya on Sat Mar 21, 2009 1:33 pm, edited 1 time in total.
alby

Re: Pretty urls and duplicate content

Post 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
Locked

Return to “[locked] Installation, Setup and Upgrade”