Need to redirect the non-existence URL's to 404 page instead of parent url This is in connection to drupal.org issue #432384.

That's when I happen to request for page "node/1/aaa/bbbb", I'm served the response for "node/1" (it's parent page).

I can understand, this is the way Drupal menu system has been designed and works for some obvious reasons. 

But I'm in a need to change this. Reason we have some aliased urls across the site, links from third party sites are taking (visitors and crawlers) to not existing page for which ideally http 404 response code and page not found to be returned. Instead Drupal showing it's parent page (with http res. code 200). This is leading to duplicate page in Google webmasters and misleading our genuine users.

I have found a patch to this issue. However it is working fine only for 80% of cases, some valid urls (admin/*, sites/default/files/ * , system/ajax/*, etc.,) leads to 404 page.

Would like to hear how others are dealing with this duplicate content issue concerning SEO and possible fix!
Considering the comments of the previous answer:


Only act on 'node' pages (aliased and not).
Avoid 'page not found' repeating 2 times.


Furthermore removed the unused variable $path.

The code below also avoids a 404 for the path 'node/add'. In case you use the Entity connect module that path might be followed by a dynamic token. The URL could then look like 'node/add/page/entityconnect-form-hmcOTIsupNLNBI-cZ-sSvjsbFISJeOfzT0VBpg0Sbpc'. Obviously that is a path not "known" by Drupal that would otherwise incorrectly result in a 404.

/**
 * Implements hook_init().
 */
function YOURMODULE_init() {
  // Only act on 'node' pages (aliased and not) but not on 'node/add'.
  if (arg(0) === 'node' &amp;&amp; arg(1) !== 'add') {
    // Extract different variables that Drupal utilizes for routing.
    $menu_item = menu_get_item();
    $href = $menu_item['href'];     // node/1
    $current_path = current_path(); // node/1/broken

    // Check if the actual path ($current_path) is different than the Drupal assumption ($href).
    if ($href != $current_path) {
      // Redirect user to 404 page which will handle the HTTP response as well.
      drupal_not_found();
      // Avoid 'page not found' repeating 2 times.
      drupal_exit();
    }
  }
}


UPDATE:
There is now a Drupal 7 module Force 404 that solves just this.