Dashes vs Underscores for SEO
There has been a lot of debate about how Google indexes URLs and whether underscores are better for Search Engine Optimization or would dashes give better results?
I have yet to find a proper conclusion to that debate, though due to another realization, I’m now inclined in favor of dashes. Here’s why:
I’ve been using underscores for most of my filenames and URLs and have been avoiding dashes like the plague, probably because it felt like I was subtracting something and because underscores look a little neater.
However, if you know anything about regular expressions, you’ll know that \w is commonly used to match characters or words in a string. In standard regex \w will only match the letters a-z, A-Z and the underscore character.
This means that in a string such as That-the-quick-brown_Fox, \w* will have four matches (“That”, “the”, “quick” and “brown_Fox”) instead of five. If I was writing a script to chop up URLs and index the letters, this is what I’d get.
Even if Google has updated their algorithms to treat underscores and dashes similarly, chances are, most other search engines, applications and websites have not. Therefore, from now onwards, I’m sticking to the da4shes whenever I can. WordPress already sets the URL using dashes, but the same should come in handy for custom URLs and image filenames.
What are your thoughts? (More info)