Skip to main content
Duplicates in Drupal Facet API Pretty Paths

In Drupal 7 when using filters based on Facet API and Facet API Pretty Paths modules by default there's a serious SEO problem - huge growth of duplicate pages which don't actually exist but have 200 OK server response. So, if you add any word to URL, instead of 404 page we get indexable result from created by us Views for Facett Paths with all appearing consequences for SEO.

This problem is inherent not only for Views + Facet API and Facet API Pretty Paths, but even for any page created with Views. The solution to the problem of duplicates for both Views pages variants and Facet filters using Views + Facet API + Facet API Pretty Paths is to install the Views 404 module

But, for basic Views the module works without any extra configuration, just a simple installation, for faceted Vews a patch is required, otherwise any filter value will generate a 404 error.

To make it work for the paths generated by the Facet API Pretty Paths module as well, after installing the Views 404 module we need to go to the module file /sites/all/modules/views404/views404.module and in about line 65 after the code:

  // Add in % for each argument, as needed.
    if (count($view_arguments) > 0) {
      foreach ($view_arguments as $type => $data) {
        if (count($conflicting_in_view) < count($conflicting_in_args)) {
          $path_array[] = '%';
          // Re-init variables to take into account the % in the path.
          $path = implode('/', $path_array);
          $matched = array_intersect($path_array, $args);
          $conflicting_in_view = array_diff($path_array, $matched);
          $conflicting_in_args = array_diff_assoc($args, $matched);
        }
        else {
          break;
        }
      }
    }

add this code:

	// If enable module 'current_search'.
   if(function_exists('current_search_get_searcher_options')){
   $searcher = str_replace('search_api_index_', 'search_api@', $view->base_table);
     $adapter = facetapi_adapter_load($searcher);
     // If view using 'index' form search api.
    if(!empty($adapter)){
        $active_items = $adapter->getAllActiveItems();
       // Count facet only with "pretty paths enable."
        foreach ($active_items as $key => $item) {
         $facet = facetapi_facet_load(reset($item['facets']), $searcher);
        $setting = $adapter->getFacetSettingsGlobal($facet);
        if (!empty($setting->settings['pretty_paths_disable'])) {
           unset($active_items[$key]);
        }
      }
        if (count($active_items) * 2 == count($conflicting_in_args)) {
         return;
       }
      }
   }

The Current Search Blocks (current_search) module must be enabled, otherwise nothing will work.

Subscribe

About The Author

Author of this blog. In SEO for over 10 years. In addition to SEO, I am interested in everything related to technology and earnings on the Internet, which I try to share with readers.