绝对网址的行为与相对网址相同 [英] Absolute URL's acting like relative URL's
问题描述
当我有 http://site.com 之类的链接时,点击该链接即可访问该网址。
但是,当链接只是 www.site.com
时,它会将此网址添加到父网站,因此 $ b 因此,请点击< a href ='www.site.com'>网站< / a> ;
在浏览器任务栏中创建: www.parentsite.com/www.site.com
。
如何在不使用 preg_replace
的情况下修复此问题?我对这款游戏相当新颖。
index.htm
,而绝对URL由协议,主机名和 当我在 example.com
的首页上...
-
contact.html
是一个相对地址,绝对最终结果将是http://example.com/contact.html
(浏览器将其作为内部计算) -
www.xyz.com
结果为http://example.com/www.xyz .com
images /
是一个相对地址,导致 http://example.com/images/
您需要将协议前缀(例如 http://
),使浏览器明白你的意思是一个完整的URL,并相应地对待它。
这里是关于MSDN上该问题的背景信息文章。
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 website and consequently does not go to the URL.
So, clicking on <a href='www.site.com'>site</a>
creates this in the browser taskbar: www.parentsite.com/www.site.com
.
How can I fix this without using preg_replace
? I am fairly new to this game.
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 behttp://example.com/contact.html
(the browser does this as an internal calculation)images/
is a relative address, resulting inhttp://example.com/images/
www.xyz.com
results inhttp://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.
这篇关于绝对网址的行为与相对网址相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!