1. Technology

To Slash or Not To Slash

Pros and Cons of Adding Slashes to the End of Your URLs




Image courtesy ilco from Stock.xchng

A URL is an address to a web page and has the following structure:

  1. http://—the protocol used, in this case http or web
  2. www.—optional machine name, the dot is the separator
  3. domain.—the domain name, again, the dot is a separator
  4. com—top-level domain
  5. /—separator from the domain and the server file structure
  6. directory/—any number of directories in the file system
  7. /—separator between the sub-directories and files
  8. filename—the file name of the file to be accessed
  9. .html—the extension of the file to give the browser and server a hint as to the MIME type for the file

When you’re typing a URL into a browser location bar, you only need to include lines 3 and 4 to get the browser to query the server and have that server attempt to deliver a file. You can also include line 5 (the domain trailing slash). In other words, if you type in “about.com” into a browser location bar, you will get something. Line 1, the protocol, is assumed to be “http://” and the machine name of “www” is either ignored or added depending upon how the server is configured.

Then if you want to go to a specific directory you need to add in lines 5 and 6 (the slash to separate the domain name and the directory name). You can also include line 7, but it’s not required.

That is the Question—Should You Include the Trailing Slash after Domains or Directory Requests?

If you’ve been reading my site for a while, you will know that I believe that it’s important to end domains and directory requests with the trailing slash. There are many reasons to include the slash:

  • avoiding a server-initiated redirect when it realizes that a directory was being called
  • keeping load times as quick as possible by not requiring the server do extra work (see above)
  • that tells the customer and the browser that the data being requested is in a directory. Without the slash, it could be a file that simply doesn’t have a file extension.

The third situation is what informs the first two. When there is no slash at the end (or file extension), the server assumes that the last word is a file name and so first looks for a file without a file extension by that name. When it doesn’t find a file, then it looks for a directory and a default file (like index.html or default.htm) in that directory.

The other resason you should consider using slashes at the end of filenames is for search engine consistency. If you don’t have a cannonical name attached to one version of the URL, then the search engine may have duplicate content for the two URLs (one with the slash and one without). But in this case, the importance is less about whether you use a slash or you don’t, but that you stay consistent. However, most servers these days are configured to redirect non-slashed directories to the slash version automatically, so it shouldn’t affect search engine duplicate content at all. For more information read Google Webmaster Tools.

But What are the Reasons You Might Leave it Off?

One of the most common reasons given for leaving off the slash is that it makes it easier for people to type. This is very true. It’s one less character to type, which can be important in advertisements where space is an issue or on tools like Twitter which count characters.

Many people feel that using or not using the slash is a matter of aesthetics. If you don’t like the way the URL looks with the slash, you would leave it off.

In fact, the speed gains you might see by adding back the slash are infinitesimal. No human reader is going to notice the difference. Computers, especially web servers, are very fast and can implement the additional requests that are required to deal with the missing slash on a directory request in microseconds. But remember that there are situations where even that little advantage could be important (see: Even Small Speed Gains are Important).

When it Doesn’t Matter

There is one situation where using the slash or not using it may not matter: when you’re using a caching system like Akamai. Web caching tools like Akamai are designed to speed up the average delivery time of a website and the pages within it. So, when a browser requests a URL with a slash on the end, Akamai adds URL to the cache. And when the browser requests a URL without a slash, it adds that as a pointer to the same file. So other than the very first hit on a directory, both pages with a slash and without will load equally quickly when behind an Akamai caching server.

At the end of the day, whether you include the trailing slash or not is up to you and any business owners of the website. You should be aware of the drawbacks to leaving off the slash as well as the benefits before you make your decision, and if you feel that the speed gains (or lack of them) that you get from including the slash are offset by customer difficulty, length restrictions, or simple aesthetics, then you should do what you want to do. At the end of the day, how you handle your website is your decision, not mine.

  1. About.com
  2. Technology
  3. Web Design / HTML
  4. Before You Start a Website
  5. Domains
  6. Should You Add Slashes to the End of URLs

©2014 About.com. All rights reserved.