协议相对 URL 是相对 URL 吗? [英] Are protocol-relative URLs relative URLs?

查看:56
本文介绍了协议相对 URL 是相对 URL 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以考虑一个像这样的 协议相对 URL

So consider a protocol-relative URL like so;

//www.example.com/file.jpg

从我记事起,我脑子里就一直有一个想法,即相对于协议的 URL 实际上是绝对 URL.它们的行为与绝对 URL 完全相同,而且它们的工作方式永远不会像相对 URL 那样.我不希望这会让浏览器在

The idea I've had in my head for as long as I can remember is that protocol-relative URLs are in fact absolute URLs. They behave exactly like absolute URLs, and never do they work like relative URLs. I wouldn't expect this to make the browser go find something at

http://www.example.com///www.example.com/file.jpg

URL 定义了主机和路径(就像绝对 URL 一样),并且该方案是从使用的任何页面继承的,因此它构成了一个完整的无歧义 URL,即绝对 URL.

The URL defines the host and the path (like an absolute URL does), and the scheme is inherited from whatever the page used, and therefore it makes a complete unambiguous URL, i.e. an absolute URL.

对吗?

现在,在对此进行进一步研究后,我发现了这个答案,其中指出;

Now, upon further research into this, I came upon this answer, which states;

一个 URL 被称为 绝对 URL 如果它以方案和方案特定部分开头(这里 //http:).其他任何内容都是相对网址.

A URL is called an absolute URL if it begins with the scheme and scheme specific part (here // after http:). Anything else is a relative URL.

问题和答案都没有专门讨论与协议相关的 URL,所以我注意这可能只是措辞上的疏忽.

Neither the question nor the answer specifically discuss protocol-relative URLs, so I'm mindful that it can just be an oversight in wording.

但是,我现在在开发过程中也遇到了一个问题,即只接受绝对 URL 的系统不能使用协议相对 URL,而且我不知道这是设计使然还是由于一个错误.

However, I'm now also now running into an issue in my development, where a system that only accepts absolute URLs doesn't function with protocol-relative URLs, and I don't know if that's by design or due to a bug.

RFC3986 部分,通常与协议相关URL 还大量使用相对"一词.4.3 接着说绝对 URI 定义了一个方案.

The RFC3986 section which is often linked to in relation to protocol-relative URLs also splashes the word "relative" around a lot. 4.3 then goes on to say that absolute URIs define a scheme.

所有这些反对我最初假设的证据都让我想到了这个问题;

All this evidence against my initial assumption led me to the question;

协议相关的 URL 是相对的还是绝对的?

推荐答案

给定相对的 URL,每个相对 URL 都是一个明确的 URL.所以如果你的页面是 http://mypage.com/some/folder/ 那么你知道相对 URL this/that 对应于 http://mypage.com/some/folder/this/that 并且您知道相对 URL //otherpage.com/ 解析为 http://otherpage.com/.重要的是,如果不知道它的相关页面 URL,就无法解析它.

Every relative URL is an unambiguous URL given the URL it is relative to. So if your page is http://mypage.com/some/folder/ then you know the relative URL this/that corresponds to http://mypage.com/some/folder/this/that and you know the relative URL //otherpage.com/ resolves to http://otherpage.com/. Importantly, it cannot be resolved without knowing the page URL it is relative to.

相对 URL 是任何与 to 相关且无法自行解析的 URL.绝对 URL 不需要任何上下文来解析.

A relative URL is any URL that is relative to something and cannot be resolved by itself. An aboslute URL does not require any context whatsoever to resolve.

这篇关于协议相对 URL 是相对 URL 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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