When the browser loads a page at /somepage/something
(without a trailing slash), it interprets the path as "the file something
in the directory /somepage
". So when it sees links like
<a href="code">Link</a>
or
<a href="./code">Link</a>
it interprets them as being relative to the current directory, i.e. /somepage
, which is why they resolve to /somepage/code
.
If you want a (relative) link to /somepage/something/code
, you will need a link like
<a href="something/code">Link</a>
(Note that if your page is at /somepage/something/
(with a trailing slash), then the browser interprets /somepage/something
as the directory. In this case, your first two attempts would work as expected.)