从 URL(通常是主机名)中省略“权限”组件但指定方案(通常http:或https:)是否合法(和良好实践,并且得到很好的支持)?
例如,这些是有效的网址吗?
https:login.html (relative hostname and path)
https:/auth/login.html (relative hostname, absolute path)
Run Code Online (Sandbox Code Playgroud)
当然,预期的行为是使用当前的主机名 - 路径(相对)。
(顺便说一句,这假设//后方案是权限(主机)组件的一部分,我认为这是正确的解释)
动机是(常见)要求网站的某些页面通过 https 访问,其他页面通过 http 访问,我们希望使用相对 url 而不是绝对的(以在不同环境中进行测试)。
根据RFC 3986:
\n+.-//的一部分所以:
\nscheme:\xc2\xa0\xc2\xa0 //authority\xc2\xa0\xc2\xa0/path这意味着
\nhttps://stackoverflow.com/auth/login.html\n\\____/\\_________________/\\______________/\n | | |\nscheme authority path\nRun Code Online (Sandbox Code Playgroud)\n权限是可选的,这意味着以下内容也有效:
\nhttps:/auth/login.html\n\\____/\\______________/\n | |\nscheme path\nRun Code Online (Sandbox Code Playgroud)\nRFC 指出了另一条规则:
\n///总结:
\nhttps://stackoverflow.com/auth/login.html (有效的)https:///auth/login.html (无效;当没有权限时,路径不能以 // 开头)https://auth/login.html (无效;当没有权限时,路径不能以 // 开头)https:/auth/login.html (有效的)https:auth/login.html (有效的)https:/login.html (有效的)https:login.html (有效的)https:/ (有效的)https: (有效的)https:login.html: 是的https:/auth/login.html是的| 归档时间: |
|
| 查看次数: |
4743 次 |
| 最近记录: |