8

This question already has an answer here:

I am wondering why some websites have a / at the end of their URL, but others don't.

For example:

  • www.google.com/
  • but then www.khanacademy.org (No /)

marked as duplicate by John Conde Dec 15 '14 at 12:47

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Where exactly are you seeing these different URLs with or without slashes? Did you try loading them in your browser? You'll find they all show up the same (e.g. Chrome shows them without slash). – DisgruntledGoat Dec 15 '14 at 12:49
2

A slash at the end of a domain tells the server that the request is for the directory and that it should look for the default file (index.html, index.php) first.

It allows for faster loading time by telling the browser to look for the default file.

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

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

Read more here

  • 2
    This answer is incorrect. The trailing slash only applies to paths, not to domains themselves. (Your example from about.com is only talking about directories.) See webmasters.stackexchange.com/questions/31796/… – DisgruntledGoat Dec 15 '14 at 12:47
  • I suppose, but isn't a domain routed as a path by the server? – Wold Dec 15 '14 at 20:51
  • @DisgruntledGoat No, his answer is correct. – Rob Dec 16 '14 at 2:31
  • 1
    @Rob No it's not. The quoted text is correct but that's talking about directories, not slashes on a domain only. See the question I linked and Stephen's answer below. – DisgruntledGoat Dec 16 '14 at 14:38
3

All websites can be accessed with or without a slash on the domain name. All of the following work:

In fact, when the browser requests home pages, it is required to submit the slash in the request, even if the slash is not present on the URL. This is a valid http request for example.com:

GET / HTTP/1.1
Host: example.com

This is an invalid request (because it is missing the slash):

GET  HTTP/1.1
Host: example.com

The valid request corresponds to the either URL: http://example.com/ or http://example.com. There is no functional difference between those two URLs.

Webmasters are free to include or to leave out that trailing slash when linking. It makes no difference.

  • I'd have to think about your linking not mattering statement. A GET is a GET no matter where it comes from but I'm tired and going to bed. – Rob Dec 16 '14 at 2:35
  • 1
    @Rob linking makes no difference because the two URLs are exactly equivalent. – DisgruntledGoat Dec 16 '14 at 14:44
  • @DisgruntledGoat No they're not the same. The slash indicates a directory and the absence of a slash indicates a file. If there is no file then a response is given back to the browser which redirects it to the file but the server can ignore that if it's set up to do so. – Rob Dec 16 '14 at 15:53
  • 1
    Servers can choose to ignore trailing slashes except for the one on the home page. There is no way to request the home page without a trailing slash. Bad things (infinite redirects) will happen if a server tries to redirect to remove it. – Stephen Ostermiller Dec 16 '14 at 15:57
  • @Rob sorry but Stephen is completely correct here. Remember we're talking about the root domain, not a folder. If you think we're incorrect you'll have to be more specific about what is wrong. – DisgruntledGoat Dec 17 '14 at 1:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.