Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relative Path, but for Port?

Tags:

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?

like image 914
Nyxynyx Avatar asked Nov 29 '11 20:11

Nyxynyx


People also ask

What is Port path?

The Port Path (integral section of Causeway Coast Way and Ulster Way) follows a stretch of scenic coastline between Portstewart and Portrush.

Should I use relative path or absolute path?

The main difference between absolute and relative paths is that absolute URLs always include the domain name of the site with http://www. Relative links show the path to the file or refer to the file itself. A relative URL is useful within a site to transfer a user from point to point within the same domain.

What is an example of a relative path?

A relative path is a way to specify the location of a directory relative to another directory. For example, suppose your documents are in C:\Sample\Documents and your index is in C:\Sample\Index. The absolute path for the documents would be C:\Sample\Documents.

What is relative path in API?

A Relative Path binds policies to a specific relative path location (for example /test/path ). When the API Gateway receives a request on the specified Relative Path, it invokes the specified policy or policy chain.


2 Answers

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:

  -- The URI reference is parsed into the five URI components   --   (R.scheme, R.authority, R.path, R.query, R.fragment) = parse(R);    -- A non-strict parser may ignore a scheme in the reference   -- if it is identical to the base URI's scheme.   --   if ((not strict) and (R.scheme == Base.scheme)) then      undefine(R.scheme);   endif;    if defined(R.scheme) then      T.scheme    = R.scheme;      T.authority = R.authority;      T.path      = remove_dot_segments(R.path);      T.query     = R.query;   else      if defined(R.authority) then         T.authority = R.authority;         T.path      = remove_dot_segments(R.path);         T.query     = R.query;      else         if (R.path == "") then            T.path = Base.path;            if defined(R.query) then               T.query = R.query;            else               T.query = Base.query;            endif;         else            if (R.path starts-with "/") then               T.path = remove_dot_segments(R.path);            else               T.path = merge(Base.path, R.path);               T.path = remove_dot_segments(T.path);            endif;            T.query = R.query;         endif;         T.authority = Base.authority;      endif;      T.scheme = Base.scheme;   endif;    T.fragment = R.fragment; 
like image 131
Adam Zalcman Avatar answered Oct 31 '22 11:10

Adam Zalcman


This can be achieved using JavaScript by setting the window.location.port property.

<a href="#" onclick="javascript:window.location.port=8080">go</a> 
like image 43
peterp Avatar answered Oct 31 '22 12:10

peterp