Avoid Spaces in Filenames - Use Hyphens Instead
You probably don't give a lot of thought to how you name your files. As long as they're named something meaningful so you can easily identify them the future; that's all that matters, right?
Well, yes, if you're talking about files on your computer. Nowadays most operating systems will accept up to 255 characters in a filename. With the exception of a few invalid characters, you can generally call your file whatever you want.
Unfortunately there are a number limitations when it comes to filenames on the web. The primary limitation - and the one that could get you into trouble - is the fact that URL's don't allow spaces.
URL's don't allow spaces? So what does that mean?
What that means is that if you upload a file to your website with spaces in its name, a user's internet browser will have to convert those spaces into valid characters, usually using the ASCII code: %20.
To illustrate: let's say you upload a file called ""AGM Minutes 2013.pdf"" and provide a link to it on your Meetings page. So far, so good. However, when viewed in a browser, the URL that is displayed in the browser address bar will be:
Not very attractive is it?
But do URL's really matter?
Yes, for a whole heap of reasons. SEO (Search Engine Optimisation) aside, it's important that our URL's are easily readable to users, and there's also the fact that spaces in filenames can, on occasion, cause a 404 (page not found) error, which means a user can't even access the file or web page.
The solution? Replace spaces with hyphens. Now our example URL becomes:
What about underscores in URL's?
Underscores would work too right? Visually, yes. Practically, no. Matt Cutts of Google deals with this issue specifically in his blog post where he explains why hyphens have a significant SEO advantage over underscores. Specifically, if a URL uses underscores as word separators, Google will only return that URL in search results if there is an exact match between it and the search phrase.
If you have a web page called "brand_product" for example, Google will only display that page in search results if a user searches for "brand_product". Conversely, a web page called "brand-product" would be displayed in search results for "brand", "product" and "brand product".
In a Nutshell
So, to summarise:
- replace spaces in filenames with hyphens
- this applies to any file you upload to your website - web pages, images, etc
- don't use underscores - they are bad for SEO