绝对网址的行为与相对网址相同 [英] Absolute URL's acting like relative URL's

查看:83
本文介绍了绝对网址的行为与相对网址相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我有 http://site.com 之类的链接时,点击该链接即可访问该网址。



但是,当链接只是 www.site.com 时,它会将此网址添加到父网站,因此 $ b 因此,请点击< a href ='www.site.com'>网站< / a> ; 在浏览器任务栏中创建: www.parentsite.com/www.site.com



如何在不使用 preg_replace 的情况下修复此问题?我对这款游戏相当新颖。

c>被解释为相对地址,例如 index.htm ,而绝对URL由协议,主机名和



当我在 example.com 的首页上...




  • contact.html 是一个相对地址,绝对最终结果将是 http://example.com/contact.html (浏览器将其作为内部计算)

  • images / 是一个相对地址,导致 http://example.com/images/


  • www.xyz.com 结果为 http://example.com/www.xyz .com




您需要将协议前缀(例如 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 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.

这篇关于绝对网址的行为与相对网址相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆