Reputation: 1892
Assuming I am on
http://sub.example.org/path/index.htm
How would a
<a href="">Link</a>
line look if all it should do is changing the protocol to https:
https://sub.example.org/path/index.htm
without needing to know the current URL where the page is located (sub.example.org/path/index.htm
), so being relative?
Example use case: Provide a "Use secure connection (HTTPS/TLS) from now!" link on all pages.
Upvotes: 1
Views: 90
Reputation: 943537
You cannot achieve this using relative URIs. A relative URI will always start at some point and then change everything to the right of that point.
You can calculate the URL using server side code or JavaScript:
location = location.toString().replace(/^http:/, "https:");
Upvotes: 2