Closed (duplicate)
Project:
Global Redirect
Version:
6.x-1.5
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
1 May 2013 at 12:50 UTC
Updated:
31 Jul 2013 at 19:33 UTC
Find out that switching the Option Add Canonical Link ON at global redirect Module add Canonicals to all current landing pages. even if the page was a node with ?page=
Have a fix to have the right node canonical link. as you can see at this code
function phptemplate_preprocess_page(&$vars) {
global $base_url;
global $base_root;
// #RA:30.4.13 : fix noindex,follow + add page # at the title
if (isset($_GET['page'])) {
if (stripos($vars['head'], '<meta name="robots" content="index,follow" />') !== false) {
$vars['head'] = str_replace('<meta name="robots" content="index,follow" />',
'<meta name="robots" content="noindex,follow" />', $vars['head']);
}
else {
$vars['head'].= '<meta name="robots" content="noindex,follow" />' . PHP_EOL;
}
$page = $_GET['page'] + 1;
$vars['head_title'] = $vars['head_title'] . t(' - Page ') . $page;
}
if (isset($vars['node'])) {
// #RA:1.5.13 : have the right node canonical link.
$nid = $vars['node']->nid;
if((drupal_lookup_path('alias', 'node/'.$nid)!==false))
$alias = drupal_lookup_path('alias', 'node/'.$nid);
$node_url= $base_url.'/'.$alias;
$node_canonical_link = '<link rel="canonical" href="'. $node_url .'" />' . PHP_EOL;
$current_url = $base_root . request_uri();
$current_canonical_link = '<link rel="canonical" href="' . $current_url . '" />' . PHP_EOL;
if (stripos($vars['head'], $current_canonical_link ) !== false) {
$vars['head'] = str_replace($current_canonical_link,
$node_canonical_link, $vars['head']);
}
else {
$vars['head'].= $node_canonical_link;
}
}
}
Comments
Comment #1
markpavlitski commented@RajabNatshah Thanks for the suggested workaround. There is an ongoing discussion of this issue in #1805904: Omit query parameters when generating canonical urls.
Comment #2
rajab natshahmarkpavlitski that one for D7.. This one is for D6 .. An old site.
Comment #3
markpavlitski commented@RajabNatshah typically if the issue exists in multiple versions it would be fixed in the current version (7.x) first, and then back-ported.
Comment #4
rajab natshahAgree with you Mark. I had a quick look at your patch.
Just, hope that the client select to upgrade to D7.. If not I may play around with your patch for D6
Comment #5
markpavlitski commentedGreat! Please feel free to post a D6 patch if you get it working.
Otherwise I may have time to port it if the first patch is accepted.
Comment #5.0
markpavlitski commentedbetter coding