Trailing slashes in URLs

When trailing slashes matters, and when they Dont. This article is about trailing slashes in URLs.

1530 views
d

By. Jacob

Edited: 2019-09-30 02:01

The Trailing slash is just as important as every other single character in URLs – http://beamtic.com/somepage/ is not the same as http://beamtic.com/somepage – but there are servers that incorrectly show the same content on both locations.

The only time when the trailing slash is superfluous, is when typing in URLs for your main domain – It doesn't matter if you type http://beamtic.com or http://beamtic.com/ – you will however find that many people claim otherwise, likely because they have not read much of the http protocol.

The trailing slash is always sent when a bare domain is requested – this is required by the HTTP specification. A request is sent to the host, along with a requested path. The path can not be empty, so a trailing slash is always included. The trailing slash can be said to represent the root of your domain.

What about directories?

Below would all be unique urls, but could easily hold the same content.

http://beamtic.com/
http://www.beamtic.com/
https://beamtic.com/
http://beamtic.com/index.html
http://beamtic.com/this-is-a-web-page/
http://beamtic.com/this-is-a-web-page

Webmasters should normally choose their Canonical URL carefully, to make sure that content is only available where intended, and will not generate duplicate content in the SERPs.

Another valid concern is around using the non slash version vs the slashed version when linking to bare domains – so let us be clear about this – not including a slash at the end of your domain, is not harmful. But the correct way to link, would be to include it. I.e.

<a href="http://beamtic.com/">Beamtic</a>

Doing it without the slash will however do no harm, as it will always be included automatically – it also will not make you lose linkjuice.

When http://beamtic.com/dir is requested, most webservers will first check to see if there is a file named dir – if that was not the case, they will then check if there is a directory named as such, and then do a redirect to http://beamtic.com/dir/ if a directory was found – otherwise it will simply throw out a normal 404 not found error.

Performance and Trailing slashes

Trailing slashes can have a slight performance impact depending on how the server is configured. If for example it has been configured to check for the existence of directories – where a requested page could not be found – there will be a slight delay due to the additional HTTP request if a directory is found.

See also

  1. How to Block or 404 out your Index
  2. Absolute and Relative Paths

Tell us what you think:

  1. An in-dept look at the use of headings (h1-h6) and sections in HTML pages.
  2. Pagination can be a confusing thing to get right both practically and programmatically. I have put a lot of thought into this subject, and here I am giving you a few of the ideas I have been working with.
  3. The best way to deal with a trailing question mark is probably just to make it a bad request, because it is a very odd thing to find in a request URL.
  4. How to optimize image-loading and automatically include width and height attributes on img elements with PHP.
  5. HTTP headers are not case-sensitive, so we are free to convert them to all-lowercase in our applications.

More in: Web development