假设我在
http://sub.example.org/path/index.htm
<a href="">Link</a>
行查看是否应该将协议更改为https:
https://sub.example.org/path/index.htm
没有需要知道当前URL的页面所在(sub.example.org/path/index.htm
),所以是相对的?
示例用例:在所有页面上提供"从现在开始使用安全连接(HTTPS/TLS) !"链接
使用相对uri无法实现这一点。相对URI总是从某一点开始,然后将所有更改到该点右侧。
您可以使用服务器端代码或JavaScript计算URL:
location = location.toString().replace(/^http:/, "https:");