Is it possible have non-existent views paths 404, but to allow facets and parameter searches?

Most of the answers to this question for base views, are either for Drupal 6, or use Mikeytown's excellent Views404 module.

However this isn't an option if you're using faceted search. Using Views404 will return 404s for all of your faceted pages.

Is there a general way to catch when views isn't hitting a facet or an allowed parameter?

  • 1
    If you're using contextual filters for your facets (which isn't really standard) you could potentially use the validation system in contextual filters to change the output. – Darvanen Sep 29 '15 at 0:12
  • @Darvanen hmm not using them unfortunately. I'm guessing putting them in is fairly involved? – Dominic Woodman Sep 30 '15 at 23:21
  • Not sure, haven't tried it tbh, but that's what I would try to do. – Darvanen Oct 1 '15 at 2:45

The solution here was to alter the Views404 module.

The module works by running a single hook_views_pre_view. This function runs a series of tests and if none of them pass returns a 404.

I added in an extra set of tests which would pass on my facets and so avoid the 404.

This problem doesn't exist with all facets. The problem comes because I'm using Facet API Pretty Paths. It turns:




And while views404 will allow para-metered search, it won't allow folders unless they pass one of the tests.

I altered my facet pretty paths in the UI, so one of the labels was country and all the rest began with 'filter':


  • Country Facet: Pretty path alias = country
  • Every other facet: Pretty path alias = filter_x

I then added the following code to views 404

$args_passed = 0;
foreach($args as $arg) {
  if($arg == 'country') {
  } elseif(is_int(strpos($arg, 'filter'))) {

if($args_passed == (count($args)-1)/2) {

Facets always come in pairs, so it goes through every arg and looks for either country or filter. If if finds half of the url arguments are facet_labels then that's a pretty strong indicator this is a genuine path and shouldn't throw a 404.

  • Actually I all needed from this was to know about the Views 404 module. Thanks for the info. – Patrick Jan 31 '17 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.