Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URLs: Dash vs. Underscore [closed]

From Google Webmaster Central

Consider using punctuation in your URLs. The URL http://www.example.com/green-dress.html is much more useful to us than http://www.example.com/greendress.html. We recommend that you use hyphens (-) instead of underscores (_) in your URLs.


Here are a few points in favor of the dashes:

  • Dashes are recommended by Google over underscores (source).
  • Dashes are more familiar to the end user.
  • Dashes are easier to write on a standard keyboard (no need to Shift).
  • Dashes don't hide behind underlines.
  • Dashes feel more native in the context of URLs as they are allowed in domain names.

It's not just dash vs. underscore:

  • text with spaces
  • textwithoutspaces
  • encoded%20spaces%20in%20URL
  • underscore_means_space
  • dash-means-space
  • plus+means+space
  • camelCase
  • PascalCase
  • " quoted text with spaces" (and single quote vs. double quote)
  • slash/means/space
  • dot.means.space

Google did not treat underscore as a word separator in the past, which I thought was pretty crazy, but apparently it does now. Because of this history, dashes are preferred. Even though underscores are now permissible from an SEO point of view, I still think that dashes are best.

One benefit is that your average semi-computer-illiterate web surfer is much more likely to be able to type a dash on the keyboard, they may not even know what the underscore is.


This is just a guess, but it seems they picked the one that people most probably wouldn't use in a name. This way you can have a name that includes a hyphenated word, and still use the underbar as a word delimiter, e.g. UseTwo-wayLinks could be converted to use_two-way_links.

In your example, /about-us would be a directory named the hyphenated word "about-us" (if such a word existed, and /about_us would be a directory named the two-word phrase "about us" converted to a single string of non-white characters.


I used to use underscores all the time, now I only use them for parts of a web site that I don't want anyone to directly link, js files, css, ... etc.

From an SEO point of view, dashes seem to be the preferred way of handling it, for a detailed explanation, from the horses mouth http://www.mattcutts.com/blog/dashes-vs-underscores/.

The other problem that seems to occur, more with the general public than programmers, is that when a hyperlink with underscores is underlined, you can't see the underscore. Advanced users will work it out, but Joe Public probably won't.

Still use underscores in code in preference to dashes though - programmers understand them, most other people don't.


Jeff has some thoughts on this: https://blog.codinghorror.com/of-spaces-underscores-and-dashes/

There are drawbacks to both. I would suggest that you pick one and be consistent.