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

markpavlitski’s picture

Status: Active » Closed (duplicate)

@RajabNatshah Thanks for the suggested workaround. There is an ongoing discussion of this issue in #1805904: Omit query parameters when generating canonical urls.

rajab natshah’s picture

markpavlitski that one for D7.. This one is for D6 .. An old site.

markpavlitski’s picture

@RajabNatshah typically if the issue exists in multiple versions it would be fixed in the current version (7.x) first, and then back-ported.

rajab natshah’s picture

Agree 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

markpavlitski’s picture

Great! 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.

markpavlitski’s picture

Issue summary: View changes

better coding