Avoiding Soft-404's for empty Drupal Taxonomies and Ubercart Categories

  • Posted on: 2 May 2013
  • By: agittins

If you spend any time in Google Webmaster tools and run a drupal site you've probably come across a collection of "Soft-404" warnings from google. While not a critical SEO task I do think it provides just one more "signal" to google about the quality of your site.

This happens a lot if you have empty taxonomy terms (ie, terms that exist but don't have any nodes belonging to them) - for us that happens with our product catalog where products are discontinued or where a product category is imported but the products within them haven't yet been published.

Slightly related to this issue is this one http://drupal.org/node/425984 which addresses getting ubercarts categories into the xml-sitemap (and my comment at the bottom which explains how to get all/most of taxonomy to point into the catalog pages rather than taxo views).

I hacked core's taxonomy module (and have done the necessary ritual self-flagellation required of this most mortal of sins) and Ubercarts catalog module to return actual 404 responses for category pages without content. These patches are against Drupal 6.

index 027ead3..1992341 100644
--- a/uc_catalog/uc_catalog.pages.inc
+++ b/uc_catalog/uc_catalog.pages.inc
@@ -147,6 +147,13 @@ function theme_uc_catalog_browse($tid = 0) {
       $cat_rows[] = $row;
     }
     $output .= $catalog->description;
+
+               // AJG - no products, no sub-categories, we should 404.
+               if ( count($child_list) == 0 ){
+                       drupal_set_header('HTTP/1.1 404 Not Found');
+                       $output .= '

'. t('There are currently no products in this category.') .'

'; + } + $output .= theme('table', array(), $cat_rows, array('class' => 'category')); }

--- taxonomy.module.original    2013-04-02 09:29:09.000000000 +1000
+++ taxonomy.module     2013-05-02 09:12:39.000000000 +1000
@@ -1187,6 +1187,8 @@
     $output .= theme('pager', NULL, variable_get('default_nodes_main', 10), 0);
   }
   else {
+    # AJG - patch to send 404's for empty taxonomies - makes google happier and makes sense. See http://drupal.org/node/120255#comment-513319
+    drupal_set_header('HTTP/1.1 404 Not Found');
     $output .= '

'. t('There are currently no posts in this category.') .'

'; } return $output;

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.