Skip to main content

Non-existent URLs in Views 2

Views 2 serves pages with for non-existent URLs instead of presenting a 404 Not Found Error.

A view with page display path set to blog creates a valid link at example.com/blog. This will show a list of blog posts, with an individual article at example.com/blog/new-article. However, an accidental link to example.com/blog/accidental-link will provide content from example.com/blog instead of the expected 404 Not Found Error, since no valid content exists there. This is a usability as well as SEO issue.

Searching discussions on Drupal and Groups.Drupal yielded the right answers. The solution is to edit the view by adding an Argument of Node: Nid. Set it to Display all values, Validator: Node, and Argument type of Node ID. Set Action to take if argument does not validate: Hide view / Page not found (404). Update the Argument and save the view.

Test at example.com/blog/accidental-link for a 404 Not Found Error - so often dreaded, this time desired!

For flexible error pages, take a look at the CustomError module.

Share this post