Multiple slashes in the URL

Today, I have seen a reply to one of my merged pull requests at work. Basically, what I did was the equivalent of using the double slash in the URL.

The relevant part of the code, changed to the minimal example, would be something like:

let baseUrl = ''
if (region === 'EU') {
    baseUrl = '';

const domainUrl = `${baseUrl}/v4/domains`

Now, when actually resolving this URL, they would end up with the double slash - as either or . So one of my teammates wondered, if this would cause the problems.

A bit surprisingly, the answer is no. Looking at the logs, I can see that we are returning the data we expect, so the calls do work as expected. Surprisingly, since the URL with and without the double slash is not the same.

I do remember, that I did had to debug once a problem, when using the last slash in the path produced different results, then if it was not included. Sigh. I can understand these bugs, but I am not really that detail oriented, so I miss things like that. Case in point - this case needed to be pointed at me as well.

It can be ignored only if the domain root is called, since

An empty abs_path is equivalent to an abs_path of "/".

from the HTTP 1.1 specifications [1].

But a lot of times it does work. I have tested a couple of sites, and it seems that at least for multiple slashes behind the domain, most of them work.

  • GitHub - works
  • StackOverflow - works after domain, does not work inside of path
  • Gmail - works
  • Hacker News - works
  • Reddit - works after domain, does not work inside of path
  • Outlook Calendar - redirects to Outlook email
  • AO3 works
  • - works
  • My site - works (but breaks CSS because of relative path)
  • Wikipedia - works after domain, does not work inside of path
  • Alexa - does not work
  • Youtube - works
  • Tumblr - works
  • Slack - works
  • Cal Newport blog - works
  • IndieWeb Wiki - does not work

But it is interesting to see, that some of them replace the multiple slashes with one, and some of them stay with the URL inputted in.

I guess there are a couple of reasons, why some of them work.

The first one would be for static sites. Since the part part of the URL just represents the path of the file, the multiple slashes do nothing. At least on Mac and Linux, if I use the cd command, where I add multiple slashes in the command, the command still works. There is at least one StackOverflow answer [2] that at least implies, that the same is true for Windows.

And it seems that some of the servers, like Apache, Nginx and Microsoft IIS would replace the multiple slashes with one [3] [4].

But I think that anything, that would depend on URL rewriting or matching might not deal with the multiple slashes - because why would they? They are not the same URL. Which is probably, why some of them do not work. The both Wiki ones are like that, where the slash is interpreted as part of the name instead.

So based on this, it seems that this is site specific. But it also seems to be something, that does not change frequently, since it depends on the infrastructure of the website the most.

But it seems, that from the search engine optimization perspective (if you are interesting in this sort of thing), having the same content on different URLs can still be a problem. So for one own site, you can think about how to handle them. In this case, just add a rewriting rule yourself, to solve this. There are a lot of examples on the net, how to do this [5] [6].