问题原文
原帖链接 · Jérôme Verstrynge · CC BY-SA 3.0
I have noticed that some blogs posts have links using a value starting with / in the href.
For example:
<a href="/somedir/somepage.html">My Page</a>
Does the leading / mean the path is starting from the site root?
In other words, if the site URL is www.mysite.com, the effective href value is www.mysite.com/somedir/somepage.html?
Is this a convention accepted in all browsers?
已采纳解答
原帖链接 · Simon Hayter · CC BY-SA 4.0
It's important to start a URL with a / so that the intended URL is returned instead of its parent or child.
Let's say if your browsing /cream-cakes/ then you have a link on the page that has blah.html without the forward slash it is going to attempt to visit page /cream-cakes/blah.html while with the forward slash it'll assume you mean the top level which will be domain.com/blah.html.
Generally, it's best to always use / in my experience as its more friendly when you change the structure of your site, though there is no right or wrong assuming that the intended page gets returned.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
