Search code examples
htmlurlhref

HTML href path weird behavior


I observed a weird behavior in this website: http://www.tribunalconstitucional.pt/tc/acordaos/

There is a button to print the page with the following href:

<a href="/tc/acordaos/?impressao=1"> ... </a>

Wasn't it supposed to build the link like this, repeating the /tc/acordaos/ part?

http://www.tribunalconstitucional.pt/tc/acordaos/tc/acordaos/?impressao=1

Why browsers build the link "correctly" as follows? Am I missing something in here?

http://www.tribunalconstitucional.pt/tc/acordaos/?impressao=1

Solution

  • The prefixed / in the href means the root (the hostname).

    So something like this for example.com/doo:

    href="/foo/bar" would go to example.com/foo/bar.

    If the prefixed / wasn't added, it would go to example.com/doo/foo/bar