Drupal SEO Spotlight: Hyphens or Dashes?

 

Google SEO iconThere's some controversy in the Drupal community over which characters to use to break up your site's paths. Most sites use either dashes or underscores. Personally, I prefer underscores for readability reasons. To me, it's easier to mentally parse this url:

http://www.davetech.com/drupal_consulting_services

Than this url:

http://www.davetech.com/drupal-consulting-services

SEO Implications

However, search engines don't see the world the same way you and I do. Many SEO experts recommend using dashes (also called hyphens) instead of underscores as they are considered more "Search Engine Friendly." Matt Cutts explains:

...if you have a url like word1_word2, Google will only return that page if the user searches for word1_word2 (which almost never happens). If you have a url like word1-word2, that page can be returned for the searches word1, word2, and even “word1 word2″.

But I'm Already Using Underscores!

Luckily, it's easy to change your paths with Drupal. First, if you've read my post Improve Your PageRank: Basic SEO with Drupal, you know about Pathauto, a Drupal module that lets you define patterns for how paths on your site should be generated. Pathauto makes it easy to change from underscores to hyphens.

  1. Visit /admin/build/path/pathauto
  2. Under General settings change the Separator from _ to -.
  3. Click Save configuration

At this point, all new nodes will be created with hyphens in their paths, instead of underscores.

What about existing nodes?

This doesn't do anything to existing nodes. If an existing node is edited, then Pathauto will create a new URL alias with hyphens, but failing that, the old alias will remain in place. You have two options for changing the aliases for existing nodes:

  1. Run a mysql script that updates the url_alias table and replaces all underscores with hyphens
  2. Delete all the existing aliases and re-create them with pathauto

Deleting the aliases is easy, but doing a bulk delete will also remove any custom aliases you previously used.

But all the inbound links to my site still use underscores!

Again, no problem! Open your .htaccess file, which should be in your web root. Find this line:

RewriteCond %{REQUEST_FILENAME} !-f

And paste the following code directly above the previous line:

RewriteRule ^(blog|news|content|faq)/([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ http://www.annuitydigest.com/$1/$2-$3-$4-$5-$6 [R=301,L]
RewriteRule ^(blog|news|content|faq)/([^_]*)_([^_]*)_(.*)$ http://www.annuitydigest.com/$1/$2-$3-$4 [R=301,L]
RewriteRule ^(blog|news|content|faq)/([^_]*)_(.*)$ http://www.annuitydigest.com/$1/$2-$3 [R=301,L]

These RewriteRules will use multiple 301 redirects to transform the underscores in all incoming links into hyphens. It will replace up to seven underscores in three or fewer redirects, which should be sufficient for most sites.

Did you enjoy this post? Please spread the word.