如何在不编写完整URL的情况下链接到当前域上的页面

Use*_*upt 11 html url hyperlink

假设当前的URL是 example.com/test/example

让我们说我想链接到 example.com/test/example/another

<a href="/another"> 把我联系到 example.com/another

如何在example.com/test/example/another不必将完整URL放入a标记的情况下链接到?

itd*_*ork 7

<a href="another">
Run Code Online (Sandbox Code Playgroud)

应该这样做.

编辑:我的坏,它实际上是:

<a href="./another">
Run Code Online (Sandbox Code Playgroud)

  • 实际上,不,从“example.com/test/example”中访问“another”会尝试访问“example.com/test/another”。要访问“example.com/test/example/another”,您必须链接到“./another” (2认同)
  • 好吧,“../another”从“example.com/test/example”转到“example.com/another” (2认同)

Dav*_*mas 5

如果您不希望使用绝对路径,我建议您使用根相对路径:

<a href="/test/example/another">Link text</a>
Run Code Online (Sandbox Code Playgroud)

否则,对于相对路径,itdoesntwork的答案将涵盖用例。