Forum Moderators: mack

Message Too Old, No Replies

To /slash/ or not to /slash/?

Adding a slash to the end of a URL - is this wise?

         

jetnovo

9:26 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



Hi there

When linking to another site (for example, www.example.com), should a slash "/" be added to the end of the URL?


<a href="http://www.example.com">link</a>

or

<a href="http://www.example.com/">link</a>

Obviously both seem to work, so which is the better syntax?

The Contractor

9:31 pm on Jun 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



/

bird

11:00 pm on Jun 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The HTTP standards say it's optional, but in practise it is more efficient to add the slash. That's because in the transfer protocol, the URL is split in two parts (actually more, but only two are relevant here). The first one is the domain name www.example.com, the second one is the path to a resource on that domain. If that path is empty, then the root path is assumed.

Theoretically, the server could just deliver the root document for an empty path. In reality, however, all server software existing today will return a redirect, which means that the client needs to issue a second request. That second request wastes time, and will make the response behaviour of your site feel a little less "snappy".

treeline

11:16 pm on Jun 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Very interesting, thank you!

Will having different versions out there:

.com
.com/

cause Google to confuse them being the same page, like

.com
.com/index.html

? Do we need to try and have them all the same?

jetnovo

9:40 pm on Jun 22, 2005 (gmt 0)

10+ Year Member



Thank you bird - that is VERY interesting!
I'm also curious about the secondary question above.

bird

10:51 pm on Jun 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Google will also be redirected, so no confusion happens.

john_k

12:16 am on Jun 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, for the root, there is no redirect. The HTTP 1.1 protocol stipulates that the resource portion of the request cannot be empty. So, as described by Bird, the browser assumes "/" and sends that as the requested resource.

The webserver is typically configured to serve a default resource for this scenario. For instance, an HTTP request to www.webmasterworld.com will return the HTML for the home page WITHOUT a redirect.

Any other folder, however, will normally result in a redirect being sent to the browser. A request to "http://www.webmasterworld.com/forum48" for instance will result in a 301 redirect. While a request to "http://www.webmasterworld.com/forum48/" returns the HTML for the New To Web Development forum.