链接到网站的索引页面 [英] Link to index page of website
问题描述
是否有一种方法可以链接到网站的索引页面而无需指定索引页面的名称或完整的网站URL?
Is there a way to link to the index page of a website without specifying the name of the index page or the full website URL?
我有这个:
<a href="index.htm">Home</a>
但是当我单击链接时,我的地址栏显示:
But when I click the link, my address bar shows:
mydomain.com/index.html
我希望它显示:
mydomain.com
是否可以在不将完整URL(mydomain.com
)放入href
的情况下执行此操作?如果可以,怎么办?
Can I do that without putting the full URL (mydomain.com
) in the href
? If so, how?
对于将来的观众,我还发现此问题很有帮助.
For future viewers, I also found this question helpful.
推荐答案
您可以执行以下操作:
<a href="/">Home</a>
任何href
前面带有斜杠的都是相对于根目录的.
Any href
preceded by a slash is relative the root directory.
应注意,当在浏览器中从本地硬盘驱动器查看网页时,这将导致链接无法正常工作.
It should be noted that when viewing a webpage from a local hard drive in a browser, this will cause the link not to function.
这篇关于链接到网站的索引页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!