I have a view page with a path set to foo/%/bar and an argument. When i browse to foo/123/bar/BAZ it returns the same result as foo/123/bar (where I guess it should return a 404). Has this happened to anyone and any idea how I can fix/troubleshoot it?

Thanks!

Comments

dawehner’s picture

Status: Active » Fixed

Look at every drupal site out there. Let's take drupal.org

http://drupal.org/node/892396 has the same content as http://drupal.org/node/892396/foo and http://drupal.org/node/892396/foo/bar

So this is how the drupal menu system works.

To fix this issue you could set a argument which returns 404 where the argument is present.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

lawrence’s picture

Category: support » feature
Status: Closed (fixed) » Active

Sorry to open this again, but take a look at this: http://drupal.org/project/views404

Setting this to feature request, hope I'm not crossing any boundaries. It'd be nice to have Views 404 integrated instead of having to install a whole new mod. Thanks for the great module!

merlinofchaos’s picture

Status: Active » Closed (won't fix)

You don't need a whole new mod. There's several tutorials out there. All you need to do is to add a Global: Null argument to your view at the point you want the URL to end.

Because of the way the menu system works, it's not really plausible to do this automatically, you have to do it manually and intentionally. You'll find this behavior all over Drupal, this is not just Views.

codebymikey’s picture

Issue summary: View changes

This behaviour can also be overridden for specific routes in a custom module using the following:

/**
 * Implements hook_menu_get_item_alter().
 */
function custom_module_menu_get_item_alter(&$router_item, $path, $original_map) {
  $router_path = $router_item['path'];

  if ($router_path === 'node/%' || $router_path === 'taxonomy/term/%') {
    if ($router_item['number_parts'] < count($original_map)) {
      $router_item['page_callback_original'] = $router_item['page_callback'];
      // Show a 404 response.
      $router_item['page_callback'] = 'custom_module_menu_not_found_callback';
    }
  }
}

/**
 * Callback to flag the response as not found.
 */
function custom_module_menu_not_found_callback() {
  // drupal_not_found(); drupal_exit();
  return MENU_NOT_FOUND;
}

It could be theoretically made into a contrib module which allows users to set the max amount of URL components that are allowed for a specific menu route.

codebymikey’s picture