append a slash to the domain if path is empty?

raw

README.rst

In an URL, should I append a slash to the domain?

RFC 1738: Uniform Resource Locators (URL)

RFC 1738 says the slash is optional:

; HTTP

httpurl        = "http://" hostport [ "/" hpath [ "?" search ]]
hpath          = hsegment *[ "/" hsegment ]

http://tools.ietf.org/html/rfc1738#page-18

RFC 3986: Uniform Resource Identifier (URI): Generic Syntax

RFC 3986 talks about normalization, and it recommends adding a slash:

In general, a URI that uses the generic syntax for authority with an empty path should be normalized to a path of "/".

http://tools.ietf.org/html/rfc3986#section-6.2.3

WhatWG URL spec

It also makes the slash after the domain name optional when serializing an URL:

An absolute URL must be a scheme, followed by ":", followed by either a scheme-relative URL [...]

[...]

A scheme-relative URL must be "//", optionally followed by userinfo and "@", followed by a host, optionally followed by ":" and a port, optionally followed by an absolute-path-relative URL.

[...]

An absolute-path-relative URL must be "/", followed by a path-relative URL that does not start with "/".

https://url.spec.whatwg.org/#writing

Christian Weiske Christian Weiske
owner

History