Drupal

Jun 15 2009

Disallow node discovery by ID

Recently I wondered if viewing a node via its internal path could be disallowed, making it accessible using a path alias only. With hook_menu_alter(), a router item's page callback can be changed to our own function that will check if the requested path is internal or not.

<?php
function hidenid_menu_alter(&$items) {
 
$items['node']['page callback'] = 'hidenid_check';
 
$items['node/%node']['page callback'] = 'hidenid_check';
 
$items['node/%node/view']['page callback'] = 'hidenid_check';
}

function hidenid_check($node = NULL, $cid = NULL) {
 
$path = $_REQUEST['q'];
 
  if (
strpos($path, 'node') === 0) {
   
drupal_not_found();
    return;
  }
  return
node_page_view($node, $cid);
}
?>

••• (#)

Pregnancy.org case study

Pregnancy.org home page screenshot

Since 2001, Pregnancy.org has been an informational and community resource for women about fertility, pregnancy, labor and child care. In November 2008, Pregnancy.org was relaunched in Drupal 6, with a new design and development by pingVision.