Mobile app version of vmapp.org
Login or Join
Pope3001725

: Is trailing slash automagically added on click of home page URL in browser? I am asking this because whenever I hover over a link to a home page (e.g. http://www.example.com), I notice that

@Pope3001725

Posted in: #Browsers #Url

I am asking this because whenever I hover over a link to a home page (e.g. www.example.com), I notice that a trailing slash is always added (as observed on the status bar of the browser) whether the home page link contains a href attribute that ends with a slash or not. But whenever I am on the home page, the URL on display will not have a trailing slash.

I tried entering a slash to the URL in the URL bar. And with Firebug enabled, I notice that the site always return a 200 OK status. An article here discussing this states that having a slash at the end will avoid a 301 redirection. But I am not seeing any redirection, even on this page.

Could this be a browser feature that is appending the slash?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Pope3001725

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

Yes, all mainstream browsers "append a slash" to the HTTP request when requesting a bare domain URL (ie. the homepage). This is actually necessary in order to make the HTTP request valid, which for example.com/ is:

GET / HTTP/1.1
Host: example.com


Note the / (slash) in the first line - this is the URL being requested. It is not valid to have nothing here. From RFC 2616:


Note that the absolute path cannot be empty; if none is present in the
original URI, it MUST be given as "/" (the server root).


You need to look at the HTTP request the browser makes to the server. The URL displayed in the "status bar of the browser", or even the URL in the address bar could be different - more user friendly. Google Chrome does not append the trailing slash in the status bar, although the slash is present in the request.

No 301 redirect occurs if you specify example.com (no slash) because the browser corrects the HTTP request before it is made.

Note that this is different to slashes being added to the end of URLs when there is a path/directory. eg. example.com/directory/. The article you link to seems to treat both the same and does not appear to be entirely correct IMO. If you requested example.com/directory (no slash) then the browser does not append a slash and yes, most servers will 301 redirect to example.com/directory/ (slash) - but this is dependent on the server; it could simply break! On Apache, for instance, this is dependent on the DirectorySlash directive being set to on.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme