We are all familiar with relative paths: A relative path to ./images/hello.jpg
from http://www.domain.com/hey
links to http://www.domain.com/hey/images/hello.jpg
.
Problem: How do you state a relative path to http://www.domain.com:1234
when you are at http://www.domain.com/hey
?
Simply you can write in href attribute:
This can be achieved using JavaScript by setting the
window.location.port
property.You cannot change any part of the authority (i.e. the host:port part) in relative URLs. See the algorithm described in section 5.2.2 of RFC 3986 to see how relative URLs are interpreted. Important thing to notice is that authority is simply copied from base URL or from the URL being resolved and authority's structure is never interpreted. This implies that you cannot change any of its parts, including the port part.
Here's the algorithm in pseudo-code copied from the RFC:
Simple answer: not possible. You need to use an absolute path if the host changes.