"Life is all about sharing. If we are good at something, pass it on." - Mary Berry

URI network-path reference


Categories: Programming


I’ve just updated the code to always prefix the post URI with a slash:

1if !strings.HasPrefix(p.URI, "/") {
2    p.URI = "/" + p.URI

and I think that no need to update the HTML template:

1<a href="/{{ .URI }}">{{ .Title }}</a>

as the redundant slash will be removed. But I was wrong.

Looking at the link address, instead of seeing:


I saw:


What’s going on?


The first question comes to my mind is what does href do if it begins with two slashes?

Take a look at the RFC 3986:

A relative reference that begins with two slash characters is termed a network-path reference

So, //2021 is termed a network-path relative reference. But why:

Please pay attention to the “network” in the above quote. href treated //2021 as a network address:

12^8 = 256
22021 = 256 * 7 + 229

That’s reason why http://localhost//2021 becomes


If you are not using network-path relative reference, make sure that the URI has only one forward slash.

Happy learning.

Tags: uri

Edit on GitHub

Related Posts: