Fix SEO problem in drupal (give 301 to node/xx request)

this was a problem with :

could be accessed from /node/442

Solution is to redirect all /node/[0-9]* url to the aliased one
… and is very simple in code:

includes/ :

function drupal_init_path() {
  if (!empty($_GET['q'])) {
    // add this conditional
    if(preg_match('/node\/[0-9]*$/',$_GET['q'])) {
      include "includes/";
      $newq = trim(url($_GET['q']),'/');
      if($newq!=$_GET['q']) {
    $_GET['q'] = drupal_get_normal_path(trim($_GET['q'], '/'));
  else {
    $_GET['q'] = drupal_get_normal_path(variable_get('site_frontpage', 'node'));

drupal_init_path() is called in bootstrap as sixth pass and find the internal path (like /node/[0-9]*)
Here I check if the request contains already a normal path, check if there is
aliased path, if so goto that path and give 301

update (16 August, 2010)
is better to use this (add conditional and goto) in custom_url_rewrite_inbound() function:
and do not touch drupal main code

see also