html - HTML href 路径奇怪的行为
问题描述
我在这个网站上观察到一个奇怪的行为:http ://www.tribunalconstitucional.pt/tc/acordaos/
有一个按钮可以打印以下页面href
:
<a href="/tc/acordaos/?impressao=1"> ... </a>
不是应该像这样建立链接,重复/tc/acordaos/
部分吗?
http://www.tribunalconstitucional.pt/tc/acordaos/tc/acordaos/?impressao=1
为什么浏览器“正确”构建链接如下?我在这里错过了什么吗?
http://www.tribunalconstitucional.pt/tc/acordaos/?impressao=1
解决方案
/
中的前缀href
表示根(主机名)。
所以像这样的东西example.com/doo
:
href="/foo/bar"
会去example.com/foo/bar
。
如果没有添加前缀/
,它将转到example.com/doo/foo/bar