Absolute URL's acting like relative URL's

后端 未结 1 570
轮回少年
轮回少年 2020-12-21 02:08

When I have a link like http://site.com, clicking it goes to that URL just fine.

But when the link is just www.site.com, it adds this URL to the parent

相关标签:
1条回答
  • 2020-12-21 02:32

    Because www.parentsite.com is interpreted as a relative address, like for example index.htm, as opposed to an absolute URL which consists of protocol, hostname, and path.

    When I'm on example.com's front page....

    • contact.html is a relative address, the absolute end result will be http://example.com/contact.html (the browser does this as an internal calculation)

    • images/ is a relative address, resulting in http://example.com/images/

    • www.xyz.com results in http://example.com/www.xyz.com

    You need to prefix the protocol (eg. http://) to make the browser understand that you mean a full URL, and treat it accordingly.

    Here's a background info article on the issue on MSDN.

    0 讨论(0)
提交回复
热议问题