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

URI network-path reference

2021-09-23

Problem

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
3}

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:

1http://localhost//2021/09/23/uri-network-path-reference

I saw:

1http://0.0.7.229/09/23/uri-network-path-reference

What’s going on?

Troubleshooting

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

Read More...