Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do web browsers always send a trailing slash after a domain name?

Tags:

browser

http

Is there consistency and/or a standard on how browsers send a url to a host related to trailing slashes?

Meaning, if I type in http://example.com in the address bar of a web browser, is the browser suppose to add a trailing slash (http://example.com/) or not?

like image 539
Hank Avatar asked Apr 05 '10 21:04

Hank


People also ask

Do browsers add trailing slash?

The trailing slash on the root domain does not matter However, different browsers may sometimes show the URL as either having a trailing slash or not when you look at the address bar. In some cases, the URL displays without a trailing slash in the address bar.

Should you have a trailing slash at the end of URLs?

If your site has a directory structure, it's more conventional to use a trailing slash with your directory URLs (for example, example.com/directory/ rather than example.com/directory ), but you can choose whichever you like. Be consistent with the preferred version. Use it in your internal links.

Why do some URLs have a trailing slash?

A trailing slash is a forward slash placed at the end of a URL. It's usually used to indicate a directory (as opposed to a file), but in SEO it can affect your rankings. Take a look at the URLs below and guess which one is 'correct'. Note that one of them has a trailing slash at the end.

Which slash is used for domain?

org or . ca); they do technically not form part of the name itself. The first slash in a website address after the domain name indicates the break between the text making up the domain information and text indicating the location of the particular file on the relevant server that hosts the website.


2 Answers

The HTTP request sent from the browser to the server does not include the domain name, only the "path" portion (starting from the first slash after the domain name). Since the path cannot be empty, a / is sent in that case.

A sample GET request for the root of a web site might be:

 GET / HTTP/1.0 

The / above cannot be omitted.

like image 178
Greg Hewgill Avatar answered Sep 29 '22 16:09

Greg Hewgill


As RFC 2616 tells:

3.2.2 http URL

The "http" scheme is used to locate network resources via the HTTP
protocol. This section defines the scheme-specific syntax and
semantics for http URLs.

http_URL = "http:" "//" host [ ":" port ] [ abs_path [ "?" query ]]

If the port is empty or not given, port 80 is assumed. The semantics
are that the identified resource is located at the server listening for TCP connections on that port of that host, and the Request-URI for the resource is abs_path (section 5.1.2). The use of IP addresses in URLs SHOULD be avoided whenever possible (see RFC 1900 [24]). If the abs_path is not present in the URL, it MUST be given as "/" when used as a Request-URI for a resource (section 5.1.2). If a proxy receives a host name which is not a fully qualified domain name, it MAY add its domain to the host name it received. If a proxy receives a fully qualified domain name, the proxy MUST NOT change the host name.

Read more: http://www.faqs.org/rfcs/rfc2616.html#ixzz0kGbpjYWa

5.1.2 Request-URI
...
For example, a client wishing to retrieve the resource above directly from the origin server would create a TCP connection to port 80 of the host "www.w3.org" and send the lines:

   GET /pub/WWW/TheProject.html HTTP/1.1    Host: www.w3.org 

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

Read more: http://www.faqs.org/rfcs/rfc2616.html#ixzz0kGcaRbqU

like image 28
Dor Avatar answered Sep 29 '22 14:09

Dor