Drupal 7 – Show page not found if view argument exists

Assume we have a Views page which does not have a contextual filter setting and the view path is /eureka. If you provide an argument in the url such as /eureka/abc, the argument is ignored and the Views page will return all view rows. But sometimes we may want to show the user a page not found instead of return all rows. This can be done by adding a Global: Null argument in the contextual filter.

1. Add a Global: Null input in the View Contextual Filters settings.

2. Check the Specify validation criteria option and select PHP Code as validator.

if (empty($argument)) {
  return TRUE;
} else {
  return FALSE;


Done =)

5 thoughts on “Drupal 7 – Show page not found if view argument exists”

  1. Hi, Thanks for this post, my site have the format url is domain/casinos, it will be return full list of casinos, but when I got some domain/casinos/aaa, or domain/casinos/bbb it still return a full list from the page, I found more result on drupal community but working incorrect. This page very useful and save a lot my time, thanks again.


  2. Thanks – just what I needed. Was driving me crazy trying to get a view to ONLY show results when the actual URL is not entered.


  3. I applied it to my archive which has created year and month contexual filters.This is not working for me showing again blank screen


Leave a Reply to John Tang Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.