Why Do URLs Often End With a Slash?

How Slashes at the End of URLs Speed Up Loading Times

Smart Tablet on Gray
Jeffrey Coolidge/Digital Vision/Getty Images

One thing that all websites have in common is a URL, or "uniform resource locator". This is the fancy way of saying the "website address". Every site has a specific address that people will use to visit the site, similar to how every phone has a specific number that people would use to call it.

One interesting aspect of URLs is the trailing slash that you often see at the end of the address. Go ahead and copy a URL from somewhere, like from a Facebook post or perhaps from a website article like this one.

Most marketers will leave the ending slash off the URL when they post it because it looks cleaner from a marketing standpoint. When you copy and paste a URL into your location bar, however, watch carefully to see if it changes. Many URLs are published without the trailing slash at the end of the domain, which is what will be copied and posted into your browser, but when you visit the URL, the slash is added. Even though the URL in the link does not have the trailing slash, the slash appears in your browser window after you click.Why is that?

The Basics of the Trailing Slash

Traditionally, URLs that pointed to files did not include the trailing slash, while URLs that pointed to directories did include the trailing slash. This means that:

http://webdesign.about.com/example/ is a directory, while
http://webdesign.about.com/example is a file.

This distinction speeds up page loading because the trailing slash immediately tells the web server to go to that example directory and look for the index.html or other whatever the default file may be (this is set on the server level,but 'index' is a pretty standard file default and most servers will already be configured that way).

When you go to a URL without the trailing slash, the web server looks for a file with that name. If it doesn’t find a file with that name, then it looks for a directory and looks for the default file in that directory. This is not a best practice, since the file name in question does not include a file extension.

If, perhaps, you had two files with the same name but different extensions, like logo.png and logo.svg, the browser would not know which to display? It is therefore better to always use the file extension instead of relying on the browser to guess at which file you wanted.

Leaving Off the Slash Results in a Redirect

When you leave off the slash on a URL that is pointing to a directory, you force the server to do a redirect. While it may seem instantaneous to you, it takes slightly longer for a page to load from a redirect than from the direct URL. Every little bit adds up when it comes to website speed and page load time, so add that slash! Even if it only improves performance a tiny, tiny bit, that is a good thing and taken as a whole, all your little improvements will make a bigger difference.

Don’t Include the Slash After Filenames

The only time you shouldn’t include a slash is after a file name in the URL. For example:

Type:
http://webdesign.about.com/example.html
Not:
http://webdesign.about.com/example.html/

If you add the slash, the web server looks for a directory named "example.html," and most servers do not then try to find a file name of that name. So your customers would get a 404 error in that situation, which is not what you want at all.

 

Always Include the Slash When Linking to Your Domain With No File Name

You can speed up access to your home page by including the trailing slash on your domain name URL. For example:

http://webdesign.about.com/

While you can’t control what your readers type into their location bar for your URL, you can control what you link them to, so always include the trailing slash in your URL links, even if you leave them off in the visual display of the HTML text. That being said, if you include the slash in your marketing materials as well, you can keep your pages loading quickly for your readers, as most people type whatever is printed without adding or removing characters.

Original article by Jennifer Krynin. Edited by Jeremy Girard on 5/4/17.