Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are unnecessary slashes in a URL bad?

I noticed that https://stackoverflow.com//////////questions/4659504/ is a valid URL. However https://www.google.com//////////analytics/settings is not. Are there differences inherent in web server technologies that explain this? Should a url with unnecessary slashes be interpreted correctly or should it return an error?

like image 657
kenwarner Avatar asked Jan 11 '11 15:01

kenwarner


People also ask

What do the slashes in a URL mean?

The addition of a slash at the end of a URL instructs the web server to search for a directory. This speeds the web page loading because the server will retrieve the content of the web page without wasting time searching for the file.

Should URLs end with a slash?

Historically, a trailing slash marked a directory and a URL without a trailing slash at the end used to mean that the URL was a file. Today, however, trailing slashes are purely conventional, and Google does not care whether you use them; as long as you're consistent.

Does a trailing slash in URL matter?

Trailing slashes after the domain name don't matter These URLs are treated exactly the same and it doesn't matter which version you use.

Can URL have two slashes?

A double slash in the URL path is valid and will respond in the browser, but is typically unwelcome, as this could cause duplicate content issues if the CMS delivers the same content on two URLs (i.e. single slash and double slash).


1 Answers

First of all, adding a slash changes the semantics of a URL path like any other character does. So by definition /foo/bar and /foo//bar are not equivalent just as /foo/bar and /foo/bar/ are not equivalent.

But since the URL path is mostly used to be directly mapped onto the file system, web servers often remove empty path segments (Apache does that) so that /foo//bar and /foo/bar are handled equivalently. But this is not the expected behavior; it’s rather done for error correction.

like image 114
Gumbo Avatar answered Sep 28 '22 01:09

Gumbo